FilipBogo

H2 ex 3

Oct 23rd, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Z80 Assembler 1.73 KB | Source Code | 0 0
  1. bits 32 ; assembling for the 32 bits architecture
  2.  
  3. ; declare the EntryPoint (a label defining the very first instruction of the program)
  4. global start        
  5.  
  6. ; declare external functions needed by our program
  7. extern exit               ; tell nasm that exit exists even if we won't be defining it
  8. import exit msvcrt.dll    ; exit is a function that ends the calling process. It is defined in msvcrt.dll
  9.                           ; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
  10.  
  11. ; our data is declared here (the variables needed by our program)
  12. segment data use32 class=data
  13.    
  14.     a db 20
  15.     b db 3
  16.     c dw 2
  17.     e dd 444
  18.     x dq 40
  19.     v1 resq 1
  20.  
  21. ; our code starts here
  22. segment code use32 class=code
  23.     start:
  24.         ;(a-2)/(b+c)+a*c+e-x; a,b-byte; c-word; e-doubleword; x-qword Unsigned
  25.        
  26.         mov eax,0
  27.         mov al,[a]
  28.         sub al,2;al=a-2
  29.         mov ebx,0
  30.         mov ecx,0
  31.         mov bl,[b];bx=b
  32.         mov cx,[c];cx=c
  33.         add cx,bx;cx=b+c
  34.         mov edx,0
  35.         div cx
  36.         mov bx,ax;bx=(a-2)/(b+c)
  37.         mov eax,0
  38.         mov al,[a]
  39.         mov edx,0
  40.         mul word[c];dx:ax=a*c
  41.         shl eax,16
  42.         mov ax,dx
  43.         rol eax,16
  44.         ;we converted dx:ax to eax
  45.         add eax,ebx;ebx=(a-2)/(b+c)+a*c
  46.         mov edx,0
  47.         add eax,[e]
  48.         adc edx,0;eax=(a-2)/(b+c)+a*c+e
  49.         sub eax,dword[x+0]
  50.         sbb edx,dword[x+4];edx:eax=(a-2)/(b+c)+a*c+e-x
  51.         mov [v1+0],eax
  52.         mov [v1+4],edx
  53.         ;we assigned v1 the value of the expresion
  54.         ; exit(0)
  55.         push    dword 0      ; push the parameter for exit onto the stack
  56.         call    [exit]       ; call exit to terminate the program
  57.  
Advertisement
Add Comment
Please, Sign In to add comment