Manipulating the stack

Written by:dimport
Published by:dimport
Published on:2003-06-21 07:19:46

The stack is used as a temporary data storage area, it can be used to store information during an interruption or just to move data between registers.

An example
I will explain everything after the code:

mov ax, 123h
push ax
mov ah, 09h
int 21h
pop ax

That register ax is set to 123(hex) in the beginning then pushed into the stack, It's then set to 09(hex) to print something on the screen, then we pop the stack and set's ex to the value that was pushed into it before, that will say that ax become 123(hex) again :)
Example two
I will explain after.

mov ax 123h
mov bx, 321h
pop ax
push bx

The final values will be ax = 123(hex) and bx = 123(hex), becuse first be pushed the ax value into the stack(it keeps it after) and then moved it into bx. :)
NOTE: you can keep pushing values into the stack, it can hold more then one :)

This article was originally written by shab

This is an article from - view the original at: