0% found this document useful (0 votes)
19 views23 pages

DownloadClassSessionFile 15

The lecture covered array definitions and instructions, stack definitions and instructions, and string definitions and instructions in computer architecture. Arrays are blocks of contiguous memory locations used to store multiple variables of the same data type. The stack uses a last-in, first-out data structure to temporarily store data and address values. String instructions like LODS, STOS, MOVS, INS, and OUTS transfer data between memory locations using registers SI, DI, and flags to determine direction.

Uploaded by

Adam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views23 pages

DownloadClassSessionFile 15

The lecture covered array definitions and instructions, stack definitions and instructions, and string definitions and instructions in computer architecture. Arrays are blocks of contiguous memory locations used to store multiple variables of the same data type. The stack uses a last-in, first-out data structure to temporarily store data and address values. String instructions like LODS, STOS, MOVS, INS, and OUTS transfer data between memory locations using registers SI, DI, and flags to determine direction.

Uploaded by

Adam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

University of Salahaddin – College of Engineering

Software & Informatics Dep.

Computer Architecture II
2022-2023

Lecture 6

Lecturer Nyan D. Sallman


Lecture outline

• 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
]

.CODE ; beginning of code segment


.STARTUP
0017 B8 0000 MOV BX, OFFSET ARRAY ;address array
001A BF 0010 MOV DI , 10H ;address element 10
001D 8A 01 MOV AL,[BX+DI] ;get element 10
001F BF 0020 MOV DI,20H ;address element 20 in cleared space
0022 88 01 MOV [BX+DI],AL ;save in element 20 in cleared space
.exit
end
.DATA ; data segment beginning
0000 0032 [ DATAS DW 10 DUP(?) ;setup array of 50 words
0000
]

.CODE ; beginning of code segment


.STARTUP
0017 MOV AX,0
001A MOV ES,AX ; ES segment address is 0000
001C MOV BX,OFFSET DATAS ;save base address of array in BS
001F MOV CX,10 ; load counter of 50
0022 AGAIN: MOV AX,ES:[046CH] ;copy data in extra segment to AX
0026 MOV [BX], AX ;save in array DATAS
0028 INC BX ; { increment to
0029 INC BX ; the next element }
002A DEC CX
002B JNZ AGAIN ; repeat 50 times
.exit
end
Stack Mode

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

PUSH AX ; copy AX register to the stack


POP BX ;remove a word from stack to BX
PUSH DS ;copy DS to the stack
PUSH 1234H;copy immediate data 1234 to stack
PUSH WORD PTR[BX]
;copy a word from WORD PTR[BX] to the stack
POP CS illegal instruction

POP EAX ;remove double word from stack to EAX


PUSH EDI ;copy EDI to the stack

PUSHA ;copy AX,CX,DX,BX,SP,BP,DI and SI to stack in


order
POPA ;remove a word each time to the following
register SI,DI,BP,SP,BX,DX,CX,AX in order

PUSHAD ;the same operation of above instruction


POPAD ; but using Extended register
.CODE
.STARTUP
MOV AX,1000H
MOV BX,2000H Program to copy CX to AX, BX to
MOV CX,3000H CX, and AX to BX without using
MOV instruction
PUSH AX
PUSH BX CX AX
PUSH CX
BX
POP AX
POP CX
POP BX
.EXIT
END
AFTER PUSH ( 2Byte data)
Lower byte [SP-2] AFTER PUSH ( 1Byte data)
Higher byte [SP-1] byte value [SP-1]
SP=SP-2 SP=SP-1

AFTER POP ( 2Byte data)


AFTER POP ( 1Byte data)
Lower byte [SP] Register [SP]
Higher byte [SP+1] SP=SP+1
SP=SP+2
After Stack segment
POP AX
AX= ………………. 12FFF

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

EAX 6AB3 03800


6A 037FF

ESP 0800 B3 037FE

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 auto increment SI,DI


If D=1 auto decrement SI,DI
LODS
Loads AL,AX,EAX with data from data segment
LODSB ;AL=DS:[SI]; SI=SI±1
LODSW ;AX=DS:[SI]; SI=SI ±2
LODSD ;EAX=DS:[SI]; SI=SI±4

+ 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]

MOVSB ;ES[DI]=DS[SI] ; SI=SI±1 ; DI=DI±1


MOVSW ;ES[DI]=DS[SI] ; SI=SI±2 ; DI=DI±2
MOVSD ;ES[DI]=DS[SI] ; SI=SI±4 ; DI=DI±4
INS • Input string from input device address by [DX] to the
extra segment address by [DI]

INSB ; ES[DI]=[DX] ; DI=DI±1 (byte transfer)


INSW ; ES[DI]=[DX] ; DI=DI±2 (word transfer)
INSD ; ES[DI]=[DX] ; DI=DI±4 (double transfer)
OUTS
• Output string from data segment address by [SI] in
to output device address by [DX]

OUTSB ; [DX]=DS[SI] ; SI=SI±1 (byte transfer)


OUTSW ; [DX]=DS[SI] ; SI=SI±2 (word transfer)
OUTSD ; [DX]=DS[SI] ; SI=SI±4 (double transfer)
Repeat prefix
REP
• Added to any string data transfer except LODS
• This instruction decrement CX by one and repeat the instruction that
postfix till CX reach to zero
• REP STOSB
• REP MOVSB
• REP INSB
• REP OUTSB
Example : display 100 word to the output device
[03AC] from memory location OFFSET ARRAY
using REP
Solution :
MOV SI,OFFSET ARRAY
MOV DX,03AC
CLD
MOV CX,100
REP OUTSW

You might also like