CENG 222 – Computer Organization
Lab Work 1
16-bits Intel microprocessors
have some capabilities of moving data from register to register; register to
memory, and vice versa.
Commonly used 16-bits registers
are:
AX, BX, CX, DX, SI, DI, SP, DS
First four registers (AX, BX, CX,
and DX) consist of two 8-bits parts called high part (denoted by ‘H’) and low part (denoted by ‘L’).
AX = AH, AL BX = BH, BL CX = CH, CL DX = DH, DL
Note that the high part register
is the most significant byte and the low part is the least significant byte of
the whole 16-bits register.
Assembly instructions of moving
data using memory and registers are given below:
§
Parameters
of instructions are denoted by <…> symbols for explaining the usage of
the instruction.
§
[] braces in
Macro assembly has the same function with * operator in C language. For
example, [AX] denotes the data or memory location where AX points to.
1-
Immediate data to register
MOV
<destination register>, <data>
MOV AX, 4C00H ; AX = 4C00h
MOV DL, 120 ; DL = 120
Size
of data and destination register must be equal!
2-
Register to register
MOV
<destination register>, <source register>
MOV
AX, CX ; AX=CX
MOV CL, BH ;
CL=BH
Note
that size of destination and source registers must be the same!
3-
Memory to register (Direct addressing)
MOV
<destination register>, [<address>]
MOV
AX, [1BFFH] ; Copy 2-bytes
(word) data stored at address 1BFF to AX
MOV
DL, [offset msg] ; Copy 1-byte
data at msg to DL
Important: Size of the data read from memory is determined
by the size of the destination register!
4-
Memory to register (Indirect addressing)
MOV
<destination register>, [<register>]
MOV
AX, [BX] ; AX = (*BX)
MOV DL, [BX] ; DL = (*BX)
Important: Size of the data read from the memory location
pointed by register, is determined by the size of the destination register!
5-
Register to memory
MOV
[<register>], <source register>
MOV
[BX], DX ; *BX = DX (Writes 2 bytes)
MOV
[BX], DL ; *BX = DL (Writes 1 byte)
MOV
[1BFFH], AX ; *(1BFFH) = AX; (Writes 2 bytes)
Note: Size of the data written is the size
of register.
6-
Immediate data to memory
MOV
[<register>], <data>
MOV
[BX], 20h ; *BX = 0020h
MOV
[BX], 4C00h ; *BX = 4C00h
MOV
[1BFFH], 20h ; *(1BFFH) = 20h;
If the source data is 1-byte, size of the
data written to the memory is 16-bits unless you state the size. Leading zeros
will be added automatically.
MOV [BX], 20h ; Copy the word (2-bytes) data to the
memory
; block
started at BX. (*BX = 0020h)
MOV WORD PTR
[BX], 20h ; Exactly the same as
above
MOV BYTE PTR
[BX], 20h ; Copy 1 byte (*BX
= 20h)
If the source data is 2-bytes, size of the
data written to the memory is 16-bits and you cannot state the size.
Experiments
Analyze the assembly code below:
title Register test program
.model small
.stack 100h
.data
msg db "AB",0dh,0ah,'$'
.code
main proc
mov
ax,@data
mov
ds,ax
; Add your code here
; ------------------
; ------------------
mov
ah,9
mov
dx,offset msg
int 21h
mov ax,
4c00h
int 21h
main endp
end main
|
The program above prints “AB” to
the console. The message “AB” is stored at msg in data segment. Therefore,
“offset msg” is the starting address of the string. Modify the code according
to the following experiments:
1-
Copy the second byte stored at “msg” (which is ‘B’ currently) to the first byte. The output should
be “BB”. In order to do that, load 2-bytes data stored at “msg” into a 16-bits
register. Copy one part of the register to the other part. Then, write your
register back to msg.
2-
Copy the first byte stored at “msg” (which is ‘A’ currently) to the second byte. The output
should be “AA”. To achieve this, load the first byte stored at “msg” into one 8-bits register (high or low part) and copy it onto the other part
and write the data stored in register back to msg.
3-
Load the data stored at “msg” into one register and swap the high and low parts of the
register using a temporary 8-bits
register. Then write back your “swapped” register onto msg. The output should
be “BA”.
No comments:
Post a Comment