Advertisement
palmerstone

Assembly Assignment

Sep 14th, 2012
3,253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Problem:
  2. Write a subprogram which will take input from the main program as-
  3. A-8 bit number(save in AL)
  4. B-32 bit number(save in BX:CX)
  5. C-16 bit number(save in DX)
  6. D-8 bit number(save in AH)
  7.  
  8.  
  9. Solution:
  10.  
  11. .stack 100h
  12.  
  13. .data
  14. A db 151
  15. B dd 1048576
  16. C dw 3298
  17. D db 78
  18.  
  19. .code
  20. main proc
  21.   mov al, A
  22.   mov ah, D
  23.   mov dx, C
  24.   lea si, B ;B is a double word, so to store B we have to treat it like an array
  25.   mov bx, [si]
  26.   mov cx, [si + 2] ;+2 because double word, advance 2 bytes
  27.  
  28.   call custom_function
  29.   ret
  30. main endp
  31.  
  32. custom_function proc
  33.    ;Inputs A, B, C, D in Al, (BX(High) + CX, (Low)), DX and AH respectively
  34.    ;Storing the input in the stack so that data is not lost
  35.    push ax
  36.    push bx
  37.    push cx
  38.    push dx
  39.    
  40.    ;Do, something here
  41.    
  42.    ;Restore the data in the registers
  43.    pop dx
  44.    pop cx
  45.    pop bx
  46.    pop ax
  47.    
  48.    ret
  49. custom_function endp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement