FilipBogo

H3

Oct 29th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Z80 Assembler 2.18 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. ;Given the words A and B, compute the byte C as follows:
  13. ;the bits 0-5 are the same as the bits 5-10 of A
  14. ;the bits 6-7 are the same as the bits 1-2 of B.
  15. ;Compute the doubleword D as follows:
  16. ;the bits 8-15 are the same as the bits of C
  17. ;the bits 0-7 are the same as the bits 8-15 of B
  18. ;the bits 24-31 are the same as the bits 0-7 of A
  19. ;the bits 16-23 are the same as the bits 8-15 of A.
  20. segment data use32 class=data
  21.     ; ...
  22.     a dw 01001011111001111b
  23.     b dw 01011110010101100b
  24.     c resb 1
  25.     d resd 1
  26. ; our code starts here
  27. segment code use32 class=code
  28.     start:
  29.         ; ...
  30.         ;a)
  31.         ;1)
  32.         mov eax,0
  33.         mov ebx,0
  34.         mov ecx,0
  35.         mov ax,[a]
  36.         and ax,011111100000b
  37.         shr ax,5;the bits 5-10 from a are stored in ax
  38.         ;2)
  39.         mov bx,[b]
  40.         and bx,0110b;we get bits 1-2
  41.         shl bx,5
  42.         or ax,bx; we get the value for c in al
  43.         mov [c],al
  44.         ;b)we also create the value of d in eax
  45.         ;1)
  46.         shl ax,8;move the bits from c to the position 8-15
  47.         ;2)
  48.         mov ebx,0
  49.         mov bx,[b]
  50.         and bx,01111111100000000b
  51.         shr bx,8
  52.         or ax,bx;the lower part of d is in ax
  53.         ;3)we just move a in cx and rotate it and then move it to the extended
  54.         mov cx,[a]
  55.         ror cx,8
  56.         shl ecx,16
  57.         or eax,ecx
  58.         mov [d],eax
  59.        
  60.        
  61.        
  62.        
  63.        
  64.        
  65.        
  66.         ; exit(0)
  67.         push    dword 0      ; push the parameter for exit onto the stack
  68.         call    [exit]       ; call exit to terminate the program
  69.  
Advertisement
Add Comment
Please, Sign In to add comment