DownloadClassSessionFile 15
DownloadClassSessionFile 15
Computer Architecture II
2022-2023
Lecture 6
• Array definition
• Stack definition and instructions
• String definition and instructions
Array Definition
MEMORY
DI
ARRAY+5
Element ARRAY +4
ARRAY+3
ARRAY+2
BX ARRAY+1
ARRAY
ARRAY
.DATA ; data segment beginning
0000 0010 [ ARRAY DB 16 DUP(?) ;setup array of 16 element
00
]
0010 29 DB 29H ;element 16 contain 29h
0011 001E [ DB 30 DUP(?)
00
]
EAX 12
EBX 12 34 34
ECX
EDX
ESP +
SS *10H
PUSH BX
Stack Mode
EAX
EBX
ECX 12 34 12
EDX 34
ESP +
SS *10H
POP CX
Stack instruction
PUSHF ; copy flag register to stack
PUSHFD ; copy extended flag to stack
POPF ;remove a word from stack to F register
POPFD
; remove double word from stack to Extended F
SP=800+2=802 h
60B5
EAX 0000 60 03801
B5 03800
ESP 0800
0802
CS
DS
SS 0300 +
ES 03000 03000
Stack segment
After
PUSH AX 12FFF
SP=800-2=7FE h
7FE
CS
DS
SS 0300 +
ES 03000 03000
String Data Transfer
String instruction :
•LODS
•STOS
•MOVS
•INS
•OUTS
Notes these operation depend on SI,DI, D(Flag)
Direction flag (D)
• CLD ;clear Direction flag (D=0) forward direction
• STD ;set direction flag (D=1) reverse direction
+ if D=0
- if D=1
DATA SEGMENT
1FFFF
EAX A0 11001
A032
32 11000
ESP
EBP
ESI 1000
EDI 10000
DS 1000 + 11000
10000
EXAMPLE : LODSW
STOS
stores AL,AX,EAX to the extra segment
• STOSB ; ES:[DI]=AL ; DI=DI±1
• STOSW ; ES:[DI]=AX ; DI=DI ±2
• STOSD ; ES:[DI]=EAX ; DI=DI± 4
MOVS
Transfer data from memory to memory directly
DS:[SI] ES:[DI]