FilipBogo

H2 ex 2

Oct 22nd, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Z80 Assembler 1.29 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.     ; ...c+a+b+b+a
  14.     ;a - byte, b - word, c - double word, d - qword - Signed representation
  15.     a db -2
  16.     b dw -5
  17.     c dd 200
  18.     d dq -5000
  19.     v1 resq 1
  20.  
  21. ; our code starts here
  22. segment code use32 class=code
  23.     start:
  24.         ; ...
  25.        
  26.         mov eax,0
  27.         mov al,[a]
  28.         cbw
  29.         add ax,[b]
  30.         add ax,[b]
  31.         cwde
  32.         add eax,[c]
  33.         mov edx,0
  34.         cdq
  35.         add eax,dword[d+0]
  36.         add edx,dword[d+4]
  37.         mov dword[v1+0],eax
  38.         mov dword[v1+4],edx
  39.         ; exit(0)
  40.         push    dword 0      ; push the parameter for exit onto the stack
  41.         call    [exit]       ; call exit to terminate the program
  42.  
Advertisement
Add Comment
Please, Sign In to add comment