Академический Документы
Профессиональный Документы
Культура Документы
Dr.Raed Al-qadi
2009 for the example slides do not click the mouse to see the full
for the example slides do not click the mouse to see the full
for the example slides do not click the mouse to see the full
MOV
MOV instrucion has the following syntax: MOV dst,src ; just clone the src into the dst The following criteria's should be applied whereever MOV is used : 1- dst and src must be the same size. 2- dst must NOT be immediate value. 3- dst and src cant be segment registers at the same time. 4- dst and src cant be memory at the same time except with MOVS instruction ( discussed later).
for the example slides do not click the mouse to see the full
Example 1 :
*Knowing that, DS=2042H. AH SI=500H, 21 AX=214E, MOV [SI],AX ;
AL 4E 21 4E 20921H 20920H
SI=500
DS=2042H
for the example slides do not click the mouse to see the full
DS=20420H
IN/OUT
These two instructions are used to read from and to a device. IN instruction syntax: IN AL,port address; (port <=255) AL or AX can be used only. Or IN AL,DX; only DX can be used here
for the example slides do not click the mouse to see the full
IN is used to read from input device in separate I/O mode. Example 2: IN AL,KEYBOARD; true But, ADD AL,KEYBOARD; false IN AL,60H; true, means read from Device at address 60H
FFFF
for the example slides do not click the mouse to see the full
Example 3 :
The serial port is at 03F8H(>255), read a byte from the serial port.
FFFF
03F8H
0000
for the example slides do not click the mouse to see the full
Example 4 :
Define the DISPLAY device at 2430H and read a byte from it. FFFF DISPLAY EQU 2430H MOV DX,DISPLAY I/O addresses IN AL,DX
64Kbyte 2430 DX=03F8H AL=data 0000
for the example slides do not click the mouse to see the full
DISPLAY
OUT instruction
Syntax: OUT port address, AL; can be AX or AL OUT DX,AL ; Just holds for DX Example 5: Send char A to the printer at 03A0H. MOV DX,03A0H MOV AL,A OUT DX,AL
for the example slides do not click the mouse to see the full
LEA
LEA stands for load effective address, it loads a 16 bit register with the offset address of the data specified by the operand. Syntax : LEA dst,src; dst stores the address of src
for the example slides do not click the mouse to see the full
Example 6:
Fill the array AR1 with * .org 300 SI=add(AR1) .data AR1 DB 20 DUP(?) LEA SI,AR1 MOV CX,20; LP : MOV [SI],* INC SI LOOP LP
for the example slides do not click the mouse to see the full
AR1
* * * * * * * * * * * * * * * * * * * *
Cx=20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
MOV OFFSET
The same as LEA , Syntax : MOV dst,OFFSET src; store the address of src into dst.
for the example slides do not click the mouse to see the full
XLAT
XLAT called translate instruction, the operation of XLAT is changing the value of AL with the memory pointed to by (AL+BX)
AL Mem[AL+BX] dddd+mmmm AL=dddd BX=mmmm AL=data data
for the example slides do not click the mouse to see the full
More clearly the XLAT instruction converts the content of register AL, using a table. Its beginning address is contained in register BX. The content of register AL is interpreted as a relative address in the table. XLAT is the only instruction that adds 8 bit number to 16 bit number! XLAT never Affects the flags..
for the example slides do not click the mouse to see the full
Example 7:
Suppose that a seven segment LED display lookup table is stored in memory at address TABLE, now XLAT can use this table to translate the BCD number in AL to a seven segment code also in AL. Let TABLE =1000H,DS=1000H,
for the example slides do not click the mouse to see the full
0 0 0 0 0 0 0 0 1 1
0 0 0 0 1 1 1 1 0 0
0 01 0 10 1 01 1 11 0 00 0 11 1 01 1 11 0 01 0 11
1 1 1 1 1 0 0 1 1 1
11 10 01 11 11 11 11 10 11 11
110 2 5BH 000 3 4FH 101 4 66H 001 5 6DH 011 6 7DH 011 7 27H 111 8 7FH 000 9 6FH 111 for the example slides do not click 0 1the mouse to see the full 1
The code for the operation of converting is very simple using XLAT TABLE DB 3FH,06H,5BH,4FH,66H,6DH,7DH,27H,7FH,6FH MOV AL,SOME_BCD_VALUE MOV BX,OFFSET TABLE XLAT For example take 06H(6 BCD) for the initial value of AL,after translation AL contains 7DH, see the figures in the next slide.
for the example slides do not click the mouse to see the full
TABLE DB 3FH,06H,5BH DB4FH,66H,6DH BX=address (TABLE)=1000H DB 7DH,27H,7FH,6FH MOV AL,06H MOV BX,OFFSET TABLE XLAT
AL=4FH AL=06H
Temp=AL+BX=1006H AL=memory [temp] AL=4FH, which is the seven segment code of 06H
7FH 6FH
DS
TABLE
1000H
for the example slides do not click the mouse to see the full
Example 8:
Write code to read the input key from port (60H) and output the value to a 7-segemnt display at 80H.
KEYS EQU 60H; DISPLAY EQU 80H; TABLE DB3FH,06H,5BH,4FH,66H,6DH,7DH,27H,7FH,6FH LEA BX,TABLE; IN AL,KEYS; XLAT OUT DISPLAY,AL
for the example slides do not click the mouse to see the full
PUSH AX
SP=100 SP=FE
F2
31
AX
31 F2
for the example slides do not click SS=2000H the mouse to see the full
Example 10:
Assume SP=100H,SS=2000H AX=31F2H,BX=413AH,CX=FFFFH. We will see the changes in the stack after executing the following sentences : PUSH AX PUSH BX POP CX POP AX
for the example slides do not click the mouse to see the full
CH
CL
41FF
FF 3A
AH 31
AL F2
SS=2000H
BH
BL
41
3A
for the example slides do not click the mouse to see the full
Example 11:
Write code to reverse string using stack operations. STR DB HELLO,00H ; REVSTR DB 256 DUP(?) MOV CX,0; count number of bytes LEA SI,STR; LEA DI,REVSTR
for the example slides do not click the mouse to see the full
NEXT-CHAR : MOV AL,[SI] CMP AL,00 JE NEXT PUSH AX ;only care about AL INC CX; JMP NEXT-CHAR
for the example slides do not click the mouse to see the full
NEXT: CMP CX,00; check if cx =0 or the string is null JE DONE-REV POP AX MOV [DI],AL INC DI DEC CX; JMP NEXT DONE-REV: MOV [DI],00; to terminate with null
for the example slides do not click the mouse to see the full
String Instructions
String instructions
MOVS
LODS
STOS
MOVSB
MOVSW
LODSB
LODSW
STOSB
STOSW
for the example slides do not click the mouse to see the full
MOVS
*MOVSB : how does it execute? Copy byte at DS:[SI] to ES:[DI]. Update SI and DI. Note that MOVS instruction deals with SI in the data segment and DI in the extra segment. The extra segment cant be overridden here).
DS:[SI] - ES:[DI] if DF = 0 then
SI = SI + 1 DI = DI + 1
(DF is D flag)
else
SI = SI - 1 DI = DI - 1
for the example slides do not click the mouse to see the full
MOVSW
*MOVSW : how does it execute? Copy word at DS:[SI] to ES:[DI]. Update SI and DI. The same as MOVSB except we move a word not abyte, see what happens to SI and DI. DS:[SI] - ES:[DI]
if DF = 0 then
SI = SI + 2 DI = DI + 2
else
SI = SI - 2 DI = DI - 2
for the example slides do not click the mouse to see the full
Example 12:
Copy 1000 bytes from location STR1 to STR2,Both are in data segment. STR2 LEA SI,STR1 SI=add(str1) LEA DI, STR2 DI=add(str2 MOV AX,DS AX=DS MOV ES,AX ES=AX=DS MOV CX,1000; Load CX with 1000 CLD Dflag=0 STR1 REP MOVSB
for the example slides do not click the mouse to see the full
1000 bytes
1000 bytes
DS ES
Example 13:
Copy 500 words from physical address 0800:200 to physical address 4000:0300,use string instructions.
0800 is the segment address and the 200 is the offset by contrast 4000 is the segment address and 0300 is its offset
So, we begin by assigning the segments addresses to DS and ES and the offsets to SI and DI for the example slides do not click
the mouse to see the full
MOV DS,0800H MOV ES,4000H MOV SI,0200H MOV DI,0300H D=0 CLD MOV CX,500 REP MOVSW
ES=4000H
D A T A
1000 bytes
SI=200
DS=0800H
for the example slides do not click the mouse to see the full
else
DI = DI - 1 And STOSW executes the same as STOSB but DI is incremented or decremented by 2
for the example slides do not click the mouse to see the full
else
SI = SI 1 And LODSW is the same except that SI is changed by 2
for the example slides do not click the mouse to see the full
Example 14:
Write program to clear DOS-screen. MOV ES,E000; E000:800 is not the real address of video memory but here is just to illustrate the idea MOV DI,800 CLD MOV CX,25*80; since the screen is 25*80 characters and it is done by assembler MOV AX,0020H; 00 for color and 20H for space REP STOSW
for the example slides do not click the mouse to see the full
The old screen is character screen,and the characters that appear on it are stored in the video memory location,for each character 2 bytes are used one for the ASCCI and the other for the color
Black space H E L L O
HELLO
for the example slides do not click the mouse to see the full
LEA and MOV OFFSET do the same operation, they load the address of one memory location to a register. XLAT copies the memory location addressed by [AL+BX] to AL. PUSH and POP are used to store and to read from the stack, both cant deal with 8 bits register, just use 16 bits.
for the example slides do not click the mouse to see the full
String instructions are : MOVSB,MOVSW,STOSB,STOSW,LODS B,LODSW. The are used for moving or stroing or loading a whole byte or a whole word at a time, they shrink the code to minimal size at most problems Only MOVS can move data from memory to memory locations
for the example slides do not click the mouse to see the full