String Operatons
String Operatons
STACKSEGMENT
DW size DUP(‘ ‘)
STACKENDS
The STACK SEGMENT and STACK ENDS directive
Stack memory size is left undefined the entire
64KB will be used for stack.
Hold the upper 16 bits of the starting address.
Stack Pointer (SP ) register is used to hold the
offset of the last word written on the stack.
The physical address is produced by adding the SS
and SP.
SP register is automatically decremented by 2
before a word is written to stack.
TITLE TO FIND THE FACTORIAL OF NUMBERS BETWEEN 1 TO 8
;Define stack segment
STACK SEGMENT
DW 100 DUP(0) ;Set aside 100 words for stack
STACK_TOP LABEL WORD ;Assign name to word above stack top
STACK ENDS
;Define Data segment
DATA SEGMENT
NUM EQU 05 ;Number to find the factorial
OPT DB '5!=' ;Output the result
RESULT DB 6 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK
MAIN:
;Intialize DS
MOV AX,DATA
MOV DS,AX
;Initialize SS
MOV AX,STACK
MOV SS,AX
MOV SP,OFFSET STACK_TOP;Initialize stack pointer
SUB SP,0004H ;Make place in the stack for the result
PUSH and PUSHF instruction
• To add a new word to the stack we PUSH
instruction. PUSH source
CALL address-expression
Address expression specifies the register or memory
location containing the address of the procedure
Actions are taken when a CALL instruction is
executed.
The return address to the calling program is
saved on the stack, which is the offset of the
next instruction after the CALL statement.
The segment: offset of this instruction is in CS:IP
at the time the call is executed.
IP gets the address of the first instruction of the
procedure.
RET instruction
CMPSB