Programming assembly

FUCK THE POLICE

911 EVERY DAY
Code:
        segment .text
        global  main
        extern  malloc, printf, scanf

main:
.n      equ     0           ; degree of the polynomial
.a      equ     8
.b      equ     16
.p      equ     24          ; polynomial
.pp     equ     32          ; p' = derivative
.P      equ     40          ; Integral
.i      equ     48          ; loop counter
        push    rbp
        mov     rbp, rsp
        sub     rsp, 64


;       prompt for and read n
        segment .data
.n_prompt:
        db      "Enter the degree of the polynomial: ",0

        segment .text
        lea     rdi, [.n_prompt]
        xor     eax, eax
        call    printf

        segment .data
.n_scanf:
        db      "%ld",0

        segment .text
        lea     rdi, [.n_scanf]        ;scanf("%ld", &n)
        lea     rsi, [rsp+.n]
        xor     eax, eax
        call    scanf

;       allocate pp, p and P
        mov     rdi, [rsp+.n]        ;double pp[n]
        call    create
    mov     [rsp+.pp], rax

        mov     rdi, [rsp+.n]        ;double p[n]
        inc     rdi
        call    create
    mov     [rsp+.p], rax

        mov     rdi, [rsp+.n]        ;double P[n]
        add     rdi, 2
        call    create
    mov     [rsp+.P], rax

;       prompt for and read p
        segment .data
.p_prompt:
        db      "Enter %ld numbers for p: ",0

        segment .text
        lea     rdi, [.p_prompt]
        mov     rsi, [rsp+.n]
        inc     rsi
        xor     eax, eax
        call    printf            ;printf("Enter %ld numbers for p: ", n++)

;       for ( i = 0; i <= n; i++ ) {
        xor     ecx, ecx                ; i = 0
        mov     [rsp+.i], rcx
.for    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n ?
        jg      .end_for
;           scanf ( "%lf", p+i );

            segment .data
.p_scanf:   db      "%lf",0

            segment .text
            lea     rdi, [.p_scanf]
            mov     rsi, [rsp+.p]
            lea     rsi, [rsi+8*rcx]
            xor     eax, eax
            call    scanf
            mov     rcx, [rsp+.i]
            inc     rcx
            mov     [rsp+.i], rcx
            jmp     .for
;       }
.end_for:
;       prompt for and read a and b

    segment .data
.a_prompt:
    db "Enter a: ", 0

    segment .text
    lea     rdi, [.a_prompt]
    xor    eax, eax
    call    printf

        segment .data
.a_scanf:
        db      "%lf",0

        segment .text
        lea     rdi, [.a_scanf]        ;scanf("%ld", &a)
        lea     rsi, [rsp+.a]
        xor     eax, eax
        call    scanf

    segment .data
.b_prompt:
    db "Enter b: ", 0

    segment .text
    lea     rdi, [.b_prompt]
    xor    eax, eax
    call    printf

        segment .data
.b_scanf:
        db      "%lf",0

        segment .text
        lea     rdi, [.b_scanf]        ;scanf("%ld", &b)
        lea     rsi, [rsp+.b]
        xor     eax, eax
        call    scanf

;       compute p prime from p

;pp[] = derivative(n, &p[], &P[])




;for(i = 1; i<=n; i++)
;{
        xor     ecx, ecx                ; i = 1
    inc    rcx
        mov     [rsp+.i], rcx
.for2  
    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n 
        jg      .end_for2

;    double element = p[i];
    mov    rax, [rsp+.p]
    mov    r8, [rsp+.pp]
    movsd    xmm0, [rax+8*rcx]
;    int i2 = i;
    mov    rbx, rcx
;    i2--;
    dec    rbx
;    pp[i2] = element*i;
    cvtsi2sd    xmm1, rcx
    mulsd    xmm1, xmm0
    movsd    [r8+8*rbx], xmm1
        mov     rcx, [rsp+.i]
        inc     rcx
        mov     [rsp+.i], rcx
    jmp     .for2
.end_for2

;       compute P from p

;for(i = 0; i<=n; i++)
;{
        xor     ecx, ecx                ; i = 0
        mov     [rsp+.i], rcx
.for3
    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n ?
        jg      .end_for3
;    double element = p[i];
    mov    rax, [rsp+.p]
    mov    r8, [rsp+.P]
    movsd    xmm0, [rax+8*rcx]
;    P[i] = element/i;
    cvtsi2sd    [r8+8*rcx], xmm1
    mov    rcx, [rsp+.i]
    inc    rcx
    mov    [rsp+.i], rcx
    jmp    .for3
;}

.end_for3

;       compute and print p(a) and p(b)

for(i<

;       compute and print pp(a) and pp(b)

;       compute and print p(b)-p(a)

        leave
        ret

create:
        push    rbp
        mov     rbp, rsp
        shl     rdi, 3
        call    malloc
        leave
        ret

suicide-demotivational-poster.png
 
aren't you too american to be learning this? They wont hire you man. THey only want foreigners they can abuse.

Computer Science actually has one of the lowest unemployment rates out of college degrees. I'm not sure if that will hold into the future, but it looks solid now and most other disciplines are just as outsourcable anyway.
 
Computer Science actually has one of the lowest unemployment rates out of college degrees. I'm not sure if that will hold into the future, but it looks solid now and most other disciplines are just as outsourcable anyway.

Yes. They will happily burn you out for a couple years. But you really need to go into project management for any sort of stable career. Programmers are considered meat for the grinder. And if you're in management they wont even let you program, for the most part, you may start to empathize too much with the slaves.

I hate to sound so negative. I just like you bro, in a totally gay way, and want to prepare you for whats out there. But your experience could vary, i hope it does actually.
 
Computer Science actually has one of the lowest unemployment rates out of college degrees. I'm not sure if that will hold into the future, but it looks solid now and most other disciplines are just as outsourcable anyway.

I hope that you are right as both my sons are doing Computer Science degrees.
 
Yes. They will happily burn you out for a couple years. But you really need to go into project management for any sort of stable career. Programmers are considered meat for the grinder. And if you're in management they wont even let you program, for the most part, you may start to empathize too much with the slaves.

I hate to sound so negative. I just like you bro, in a totally gay way, and want to prepare you for whats out there. But your experience could vary, i hope it does actually.

How sweet.
 
Code:
        segment .text
        global  main
        extern  malloc, printf, scanf

main:
.n      equ     0           ; degree of the polynomial
.a      equ     8
.b      equ     16
.p      equ     24          ; polynomial
.pp     equ     32          ; p' = derivative
.P      equ     40          ; Integral
.i      equ     48          ; loop counter
        push    rbp
        mov     rbp, rsp
        sub     rsp, 64


;       prompt for and read n
        segment .data
.n_prompt:
        db      "Enter the degree of the polynomial: ",0

        segment .text
        lea     rdi, [.n_prompt]
        xor     eax, eax
        call    printf

        segment .data
.n_scanf:
        db      "%ld",0

        segment .text
        lea     rdi, [.n_scanf]        ;scanf("%ld", &n)
        lea     rsi, [rsp+.n]
        xor     eax, eax
        call    scanf

;       allocate pp, p and P
        mov     rdi, [rsp+.n]        ;double pp[n]
        call    create
    mov     [rsp+.pp], rax

        mov     rdi, [rsp+.n]        ;double p[n]
        inc     rdi
        call    create
    mov     [rsp+.p], rax

        mov     rdi, [rsp+.n]        ;double P[n]
        add     rdi, 2
        call    create
    mov     [rsp+.P], rax

;       prompt for and read p
        segment .data
.p_prompt:
        db      "Enter %ld numbers for p: ",0

        segment .text
        lea     rdi, [.p_prompt]
        mov     rsi, [rsp+.n]
        inc     rsi
        xor     eax, eax
        call    printf            ;printf("Enter %ld numbers for p: ", n++)

;       for ( i = 0; i <= n; i++ ) {
        xor     ecx, ecx                ; i = 0
        mov     [rsp+.i], rcx
.for    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n ?
        jg      .end_for
;           scanf ( "%lf", p+i );

            segment .data
.p_scanf:   db      "%lf",0

            segment .text
            lea     rdi, [.p_scanf]
            mov     rsi, [rsp+.p]
            lea     rsi, [rsi+8*rcx]
            xor     eax, eax
            call    scanf
            mov     rcx, [rsp+.i]
            inc     rcx
            mov     [rsp+.i], rcx
            jmp     .for
;       }
.end_for:
;       prompt for and read a and b

    segment .data
.a_prompt:
    db "Enter a: ", 0

    segment .text
    lea     rdi, [.a_prompt]
    xor    eax, eax
    call    printf

        segment .data
.a_scanf:
        db      "%lf",0

        segment .text
        lea     rdi, [.a_scanf]        ;scanf("%ld", &a)
        lea     rsi, [rsp+.a]
        xor     eax, eax
        call    scanf

    segment .data
.b_prompt:
    db "Enter b: ", 0

    segment .text
    lea     rdi, [.b_prompt]
    xor    eax, eax
    call    printf

        segment .data
.b_scanf:
        db      "%lf",0

        segment .text
        lea     rdi, [.b_scanf]        ;scanf("%ld", &b)
        lea     rsi, [rsp+.b]
        xor     eax, eax
        call    scanf

;       compute p prime from p

;pp[] = derivative(n, &p[], &P[])




;for(i = 1; i<=n; i++)
;{
        xor     ecx, ecx                ; i = 1
    inc    rcx
        mov     [rsp+.i], rcx
.for2  
    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n 
        jg      .end_for2

;    double element = p[i];
    mov    rax, [rsp+.p]
    mov    r8, [rsp+.pp]
    movsd    xmm0, [rax+8*rcx]
;    int i2 = i;
    mov    rbx, rcx
;    i2--;
    dec    rbx
;    pp[i2] = element*i;
    cvtsi2sd    xmm1, rcx
    mulsd    xmm1, xmm0
    movsd    [r8+8*rbx], xmm1
        mov     rcx, [rsp+.i]
        inc     rcx
        mov     [rsp+.i], rcx
    jmp     .for2
.end_for2

;       compute P from p

;for(i = 0; i<=n; i++)
;{
        xor     ecx, ecx                ; i = 0
        mov     [rsp+.i], rcx
.for3
    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n ?
        jg      .end_for3
;    double element = p[i];
    mov    rax, [rsp+.p]
    mov    r8, [rsp+.P]
    movsd    xmm0, [rax+8*rcx]
;    P[i] = element/i;
    cvtsi2sd    [r8+8*rcx], xmm1
    mov    rcx, [rsp+.i]
    inc    rcx
    mov    [rsp+.i], rcx
    jmp    .for3
;}

.end_for3

;       compute and print p(a) and p(b)

for(i<

;       compute and print pp(a) and pp(b)

;       compute and print p(b)-p(a)

        leave
        ret

create:
        push    rbp
        mov     rbp, rsp
        shl     rdi, 3
        call    malloc
        leave
        ret

suicide-demotivational-poster.png

Is that X86 assembler? I didn't think anybody taught low level languages these days.
 
Computer Science actually has one of the lowest unemployment rates out of college degrees. I'm not sure if that will hold into the future, but it looks solid now and most other disciplines are just as outsourcable anyway.
It also has a high burn out rate. Constantly sitting at a desk hammering out code with tons of pressure to get things done yesterday take their toll.

Some professions are more outsourceable (is there such a word?) then others. Chemist have taken a hard hit in this country due to manufacturing outsourcing. The major employer for chemist has traditionally been at manufacturing facility in support of production and in product development. Most of those jobs have gone over seas and many chemist have had to accept lower wages or learn a new field. I can imagine their frustration. Chemistry is one of the hardest majors in academia. I would not recommend any young person majoring in Chemistry unless they intend to persue an academic career. The payoff isn't worth the effort.
 
It also has a high burn out rate. Constantly sitting at a desk hammering out code with tons of pressure to get things done yesterday take their toll.

Some professions are more outsourceable (is there such a word?) then others. Chemist have taken a hard hit in this country due to manufacturing outsourcing. The major employer for chemist has traditionally been at manufacturing facility in support of production and in product development. Most of those jobs have gone over seas and many chemist have had to accept lower wages or learn a new field. I can imagine their frustration. Chemistry is one of the hardest majors in academia. I would not recommend any young person majoring in Chemistry unless they intend to persue an academic career. The payoff isn't worth the effort.

Chemical and petrochemical engineering is traditionally one of the highest paying professions for young graduates.
 
It also has a high burn out rate. Constantly sitting at a desk hammering out code with tons of pressure to get things done yesterday take their toll.

Some professions are more outsourceable (is there such a word?) then others. Chemist have taken a hard hit in this country due to manufacturing outsourcing. The major employer for chemist has traditionally been at manufacturing facility in support of production and in product development. Most of those jobs have gone over seas and many chemist have had to accept lower wages or learn a new field. I can imagine their frustration. Chemistry is one of the hardest majors in academia. I would not recommend any young person majoring in Chemistry unless they intend to persue an academic career. The payoff isn't worth the effort.

That's what I found many moons ago. I majored in Chemistry but after one job in the big bad world working for Ciba Geigy, I moved into the IT industry.
 
Chemical and petrochemical engineering is traditionally one of the highest paying professions for young graduates.

Computer science is well. But we aren't talking about pay, we're talking about quality of life. I know that's a foreign concept to a conservative, but please bear with us.
 
Computer science is well. But we aren't talking about pay, we're talking about quality of life. I know that's a foreign concept to a conservative, but please bear with us.
You mean building computers, not programming them. :D

Regarding quality of life issues, retard, that's why I chose civil engineering over the three other branches. I realize understanding how that would be inherently important to a conservative is foreign to you...
 
You mean building computers, not programming them. :D

Building computers is computer/electrical engineering, computer science and software engineering deals with the software side of things. CE does pay more on average, but not by much. CS also has a lower unemployment rate than either, strangely enough.

I've taken a few CE classes, and they are incredibly difficult. Not a path I would want to go down.
 
Code:
        segment .text
        global  main
        extern  malloc, printf, scanf

main:
.n      equ     0           ; degree of the polynomial
.a      equ     8
.b      equ     16
.p      equ     24          ; polynomial
.pp     equ     32          ; p' = derivative
.P      equ     40          ; Integral
.i      equ     48          ; loop counter
        push    rbp
        mov     rbp, rsp
        sub     rsp, 64


;       prompt for and read n
        segment .data
.n_prompt:
        db      "Enter the degree of the polynomial: ",0

        segment .text
        lea     rdi, [.n_prompt]
        xor     eax, eax
        call    printf

        segment .data
.n_scanf:
        db      "%ld",0

        segment .text
        lea     rdi, [.n_scanf]        ;scanf("%ld", &n)
        lea     rsi, [rsp+.n]
        xor     eax, eax
        call    scanf

;       allocate pp, p and P
        mov     rdi, [rsp+.n]        ;double pp[n]
        call    create
    mov     [rsp+.pp], rax

        mov     rdi, [rsp+.n]        ;double p[n]
        inc     rdi
        call    create
    mov     [rsp+.p], rax

        mov     rdi, [rsp+.n]        ;double P[n]
        add     rdi, 2
        call    create
    mov     [rsp+.P], rax

;       prompt for and read p
        segment .data
.p_prompt:
        db      "Enter %ld numbers for p: ",0

        segment .text
        lea     rdi, [.p_prompt]
        mov     rsi, [rsp+.n]
        inc     rsi
        xor     eax, eax
        call    printf            ;printf("Enter %ld numbers for p: ", n++)

;       for ( i = 0; i <= n; i++ ) {
        xor     ecx, ecx                ; i = 0
        mov     [rsp+.i], rcx
.for    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n ?
        jg      .end_for
;           scanf ( "%lf", p+i );

            segment .data
.p_scanf:   db      "%lf",0

            segment .text
            lea     rdi, [.p_scanf]
            mov     rsi, [rsp+.p]
            lea     rsi, [rsi+8*rcx]
            xor     eax, eax
            call    scanf
            mov     rcx, [rsp+.i]
            inc     rcx
            mov     [rsp+.i], rcx
            jmp     .for
;       }
.end_for:
;       prompt for and read a and b

    segment .data
.a_prompt:
    db "Enter a: ", 0

    segment .text
    lea     rdi, [.a_prompt]
    xor    eax, eax
    call    printf

        segment .data
.a_scanf:
        db      "%lf",0

        segment .text
        lea     rdi, [.a_scanf]        ;scanf("%ld", &a)
        lea     rsi, [rsp+.a]
        xor     eax, eax
        call    scanf

    segment .data
.b_prompt:
    db "Enter b: ", 0

    segment .text
    lea     rdi, [.b_prompt]
    xor    eax, eax
    call    printf

        segment .data
.b_scanf:
        db      "%lf",0

        segment .text
        lea     rdi, [.b_scanf]        ;scanf("%ld", &b)
        lea     rsi, [rsp+.b]
        xor     eax, eax
        call    scanf

;       compute p prime from p

;for(i = 1; i<=n; i++)
;{
        xor     ecx, ecx                ; i = 1
    inc    rcx
        mov     [rsp+.i], rcx
.for2  
    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n 
        jg      .end_for2

;    double element = p[i];
    mov    rax, [rsp+.p]
    mov    r8, [rsp+.pp]
    movsd    xmm0, [rax+8*rcx]
;    int i2 = i;
    mov    rbx, rcx
;    i2--;
    dec    rbx
;    pp[i2] = element*i;
    cvtsi2sd    xmm1, rcx
    mulsd    xmm1, xmm0
    movsd    [r8+8*rbx], xmm1
        mov     rcx, [rsp+.i]
        inc     rcx
        mov     [rsp+.i], rcx
    jmp     .for2
.end_for2

;       compute P from p

;for(i = 0; i<=n; i++)
;{
        xor     ecx, ecx                ; i = 0
        mov     [rsp+.i], rcx
.for3
    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n ?
        jg      .end_for3
;    double element = p[i];
    mov    rax, [rsp+.p]
    mov    r8, [rsp+.P]
    movsd    xmm0, [rax+8*rcx]
;    P[i] = element/i;nn
    cvtsi2sd    [r8+8*rcx], xmm1
    mov    rcx, [rsp+.i]
    inc    rcx
    mov    [rsp+.i], rcx
    jmp    .for3
;}

.end_for3

;       compute and print p(a) and p(b)

movsd    xmm0, [rsp+.a]
mov    rax, [rsp+.p]
movsd    xmm1, [rax]
movsd    xmm2, 0

;for(i=0; i<=n; i++)
;{

        xor     ecx, ecx                ; i = 0
        mov     [rsp+.i], rcx
.for4
    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n ?
        jg      .end_for4

;    mul = a * p[i];

    movsd    xmm1, [rax+8*rcx]
    mulsd    xmm1, xmm0

;    acc += mul;

    addsd    xmm2, xmm1
    mov    rcx, [rsp+.i]
    inc    rcx
    mov    [rsp+.i], rcx
    jmp    .for4
;}
.end_for4

    segment .data
.a_out    db    "p(a): %lf", 0

    lea    rdi, [.a_out]
    movsd    xmm0, xmm2
    xor    eax, eax
    call    printf

movsd    xmm0, [rsp+.b]
mov    rax, [rsp+.p]
movsd    xmm1, [rax]
movsd    xmm2, 0

;for(i=1; i<=n; i++)
;{

        xor     ecx, ecx                ; i = 0
        mov     [rsp+.i], rcx
.for5
    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n ?
        jg      .end_for5

;    mul = a * p[i];

    movsd    xmm1, [rax+8*rcx]
    mulsd    xmm1, xmm0

;    acc += mul;

    addsd    xmm2, xmm1
    mov    rcx, [rsp+.i]
    inc    rcx
    mov    [rsp+.i], rcx
    jmp    .for5
;}
.end_for5

    segment .data
.b_out    db    "p(b): %lf", 0

    segment    .text
    lea    rdi, [.b_out]
    movsd    xmm0, xmm2
    xor    eax, eax
    call    printf

;       compute and print pp(a) and pp(b)

movsd    xmm0, [rsp+.a]
mov    rax, [rsp+.pp]
movsd    xmm1, [rax]
movsd    xmm2, 0

;for(i=1; i<=n; i++)
;{

        xor     ecx, ecx                ; i = 0
        mov     [rsp+.i], rcx
    inc    rcx
.for6
    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n ?
        jg      .end_for6

;    mul = a * pp[i];

    movsd    xmm1, [rax+8*rcx]
    mulsd    xmm1, xmm0

;    acc += mul;

    addsd    xmm2, xmm1
    mov    rcx, [rsp+.i]
    inc    rcx
    mov    [rsp+.i], rcx
    jmp    .for6
;}
.end_for6

    segment .data
.da_out    db    "p'(a): %lf", 0

    segment .text
    lea    rdi, [.da_out]
    movsd    xmm0, xmm2
    xor    eax, eax
    call    printf

movsd    xmm0, [rsp+.b]
mov    rax, [rsp+.pp]
movsd    xmm1, [rax]
movsd    xmm2, 0

;for(i=0; i<n; i++)
;{

        xor     ecx, ecx                ; i = 0
        mov     [rsp+.i], rcx
.for7
    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n 
        jg      .end_for7

;    mul = b * p'[i];

    movsd    xmm1, [rax+8*rcx]
    mulsd    xmm1, xmm0

;    acc += mul;

    addsd    xmm2, xmm1
    mov    rcx, [rsp+.i]
    inc    rcx
    mov    [rsp+.i], rcx
    jmp    .for7
;}
.end_for7

    segment .data
.db_out    db    "p'(b): %lf", 0

    segment    .text
    lea    rdi, [.b_out]
    movsd    xmm0, xmm2
    xor    eax, eax
    call    printf

;       compute and print p(b)-p(a)

movsd    xmm0, [rsp+.b]
movsd    xmm4, [rsp+.a]
mov    rax, [rsp+.P]
movsd    xmm2, 0
movsd    xmm5, 0

;for(i=0; i<n; i++)
;{

        xor     ecx, ecx                ; i = 0
        mov     [rsp+.i], rcx
    inc    rcx
.for8
    mov     rdx, [rsp+.n]
        cmp     rcx, rdx                ; i <= n ?
        jg      .end_for7

;    mul = b * P[i];

    movsd    xmm1, [rax+8*rcx]
    mulsd    xmm1, xmm0

;    acc += mul;

    addsd    xmm2, xmm1
    mov    rcx, [rsp+.i]
    inc    rcx
    mov    [rsp+.i], rcx
    jmp    .for8
;}
.end_for8

    segment .data
.P_out    db    "P(b) - P(a): %lf", 0

    segment    .text
    lea    rdi, [.P_out]
    movsd    xmm0, xmm2
    xor    eax, eax
    call    printf


        leave
        ret

create:
        push    rbp
        mov     rbp, rsp
        shl     rdi, 3
        call    malloc
        leave
        ret

Ah, this is quite lovely, is it not?
 
Back
Top