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)
- ;Given the words A and B, compute the byte C as follows:
- ;the bits 0-5 are the same as the bits 5-10 of A
- ;the bits 6-7 are the same as the bits 1-2 of B.
- ;Compute the doubleword D as follows:
- ;the bits 8-15 are the same as the bits of C
- ;the bits 0-7 are the same as the bits 8-15 of B
- ;the bits 24-31 are the same as the bits 0-7 of A
- ;the bits 16-23 are the same as the bits 8-15 of A.
- segment data use32 class=data
- ; ...
- a dw 01001011111001111b
- b dw 01011110010101100b
- c resb 1
- d resd 1
- ; our code starts here
- segment code use32 class=code
- start:
- ; ...
- ;a)
- ;1)
- mov eax,0
- mov ebx,0
- mov ecx,0
- mov ax,[a]
- and ax,011111100000b
- shr ax,5;the bits 5-10 from a are stored in ax
- ;2)
- mov bx,[b]
- and bx,0110b;we get bits 1-2
- shl bx,5
- or ax,bx; we get the value for c in al
- mov [c],al
- ;b)we also create the value of d in eax
- ;1)
- shl ax,8;move the bits from c to the position 8-15
- ;2)
- mov ebx,0
- mov bx,[b]
- and bx,01111111100000000b
- shr bx,8
- or ax,bx;the lower part of d is in ax
- ;3)we just move a in cx and rotate it and then move it to the extended
- mov cx,[a]
- ror cx,8
- shl ecx,16
- or eax,ecx
- mov [d],eax
- ; 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