1 / 14

Stack and Subroutines

Stack and Subroutines. Module M17.1 Section 11.2. The Stack. A region of memory in the stack segment (SS) used for storing temporary data. The stack is a Last-In-First-Out (LIFO) data structure (like a stack of plates). The stack pointer points to the value on top of the stack.

zuzela
Télécharger la présentation

Stack and Subroutines

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Stack and Subroutines Module M17.1 Section 11.2

  2. The Stack • A region of memory in the stack segment (SS) used for storing temporary data. • The stack is a Last-In-First-Out (LIFO) data structure (like a stack of plates). • The stack pointer points to the value on top of the stack. • The stack grows toward lower memory addresses. That is, the stack pointer is decremented before an element is written to memory.

  3. Pushing AX on the Stack

  4. Note: Can only PUSH and POP 16-bit values

  5. Push and Pop Example 0000 B8 34 12 MOV AX,1234H 0003 BB 78 56 MOV BX,5678H 0006 50 PUSH AX 0007 53 PUSH BX 0008 58 POP AX 0009 5B POP BX

  6. Subroutines

  7. Subroutine Example 0000 E8 05 00 CALL 0008H 0003 E8 0A 00 CALL 0010H 0006 CC INT 3 0008 E8 05 00 CALL 0010H 000B C3 RET 0010 C3 RET Note: Destination address = Displacement + Offset address of next instruction 0005 + 0003 = 0008 000A + 0006 = 0010 0005 + 000B = 0010

  8. SCREEN.ASM Subroutines • deccur • decrement the screen cursor • pbyte • print the hex value of the byte in AL followed by a space • crlf • carriage return - line feed: move cursor to beginning of next line • quit • return to DOS

  9. Quit to DOS quit proc near mov ax,4C00h int 21h quit endp

  10. Stack segment Data segment Subroutines from file SCREEN.ASM

  11. numer 78 56 numer+2 34 12 denom BC 9A

  12. Must always set DS to DATA dx:ax = numer bx = denom quotient in ax remainder in dx

  13. ;save registers ;save ax in bx ;print high byte ;decrement cursor ;print low byte ;decrement cursor ;restore registers

More Related