Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bits 32 ; assembling for the 32 bits architecture
- ; declare the EntryPoint (a label defining the very first instruction of the program)
- global start
- ; declare external functions needed by our program
- extern exit ; tell nasm that exit exists even if we won't be defining it
- import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
- ; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
- ; our data is declared here (the variables needed by our program)
- segment data use32 class=data
- a db 20
- b db 3
- c dw 2
- e dd -444
- x dq 43
- v1 resq 1
- ; our code starts here
- segment code use32 class=code
- start:
- ;(a-2)/(b+c)+a*c+e-x; a,b-byte; c-word; e-doubleword; x-qword Signed
- mov eax,0
- mov ecx,0
- mov al,[b];al=b
- cbw;ax=b
- mov cx,[c];cx=c
- add cx,ax;cx=b+c
- mov eax,0
- mov al,[a]
- sub al,2;al=a-2
- cbw
- cwd
- idiv cx
- cwde
- mov ebx,eax;ebx=(a-2)/(b+c)
- mov eax,0
- mov al,[a]
- cbw
- cwd
- imul word[c];dx:ax=a*c
- shl eax,16
- mov ax,dx
- rol eax,16
- ;we converted dx:ax to eax
- add eax,ebx;eax=(a-2)/(b+c)+a*c
- add eax,[e]
- ;eax=(a-2)/(b+c)+a*c+e
- cdq
- sub eax,dword[x+0]
- sbb edx,dword[x+4];edx:eax=(a-2)/(b+c)+a*c+e-x
- mov [v1+0],eax
- mov [v1+4],edx
- ;we assigned v1 the value of the expresion
- ; exit(0)
- push dword 0 ; push the parameter for exit onto the stack
- call [exit] ; call exit to terminate the program
Advertisement
Add Comment
Please, Sign In to add comment