Microprocessor Lecture9
Microprocessor Lecture9
Microprocessor Lecture9
Execution steps:
AL 3F 0011 1111 0011 1111
– BH – 23 – 0010 0011 + 1100 0001 (2’s complement)
1C 0001 1100 1 0001 1100 (CF=0) Step 3
Ex:
;from the data segment:
DATA1 DB 4CH
DATA2 DB 6EH
RESULT DB ?
DATA_A DD 62562FAH
DATA_B DD 412963BH
RESULT DD ?
….. …..
MOV AX,WORD PTR DATA_A ;AX=62FA
SUB AX,WORD PTR DATA_B ;AX=AX – 963B
MOV WORD PTR RESULT,AX ;save the result
MOV AX,WORD PTR DATA_A +2 ;AX=0625
SBB AX,WORD PTR DATA_B +2 ;SUB 0412 with borrow
MOV WORD PTR RESULT +2,AX ;save the result
Note: PTR (Pointer) Directive is used to specify the size of the operand. Among the options for
size are BYTE, WORD, DWORD and QWORD.
Solution:
After the SUB, AX = 62FA – 963B = CCBF and the carry flag is set. Since CF=1, when
SBB is executed, AX = 625 – 412 – 1 = 212. Therefore, the value stored in RESULT is
0212CCBF.
¾ byte x byte :
• One of the operands must be in AL . The other operand can be either in a register
or in memory.
• After the multiplication the result is in AX.
¾ word x word :
• One of the operands must be in AX . The other operand can be either in a register
or in memory.
• After the multiplication the lower word is in AX and the higher word is in DX.
Ex:
DATA3 DW 2278H
DATA4 DW 2F79H
RESULT1 DW 2 DUP?
...
MOV AX,DATA3 ; load first operand into AX
MUL DATA4 ; multiply it by the second operand
MOV RESULT1,AX ; store the lower word of the result
MOV RESULT1+2,DX ; store the higher word of the result
¾ word x byte :
• Similar to word x word, but AL contains byte operand and AH must be zero.
Ex:
DATA5 DB 6BH
DATA6 DW 12C3H
RESULT3 DW 2 DUP?
...
MOV AL,DATA5 ; AL holds byte operand
SUB AH,AH ; AH must be cleared
MUL DATA6 ; byte in AL multiplied by word
operand
MOV BX,OFFSET RESULT3 ; BX points the storage for product
MOV [BX],AX ; AX holds lower word
MOV [BX]+2,DX ; DX holds higher word
1. Byte / byte
• Numerator must be in AL and AH must be set to zero
• Denominator cannot be immediate but can be in memory or in a register.
• After the division AL will have the quotient and AH will have the remainder
Ex: DATA7 DB 95
DATA8 DB 10
QUOT1 DB ?
REMAIN1 DB ?
2. word / word
• Numerator must be in AX and DX must be cleared
• Denominator can be in memory or in a register.
• After the division AX will have the quotient and DX will have the remainder
Ex:
MOV AX,10050 ;AX holds numerator
SUB DX,DX ;DX must be cleared
MOV BX,100 ;BX is used for denominator
DIV BX ;divide AX by BX
MOV QUOT2,AX ;quotient = AX = 64H (100 )
MOV REMAIN2,DX ;remainder = DX = 32H (50)
3. word / byte
• Numerator must be in AX
• Denominator can be in memory or in a register.
• After the division AL will have the quotient and AH will have the remainder
Ex:
MOV AX,2055 ;AX holds numerator
MOV CL,100 ;BX is used for denominator
DIV CL ;divide AX by CL
MOV QUO,AL ;AL holds the quotient = AL = 14H (20)
MOV REMI,AH ;AH holds the remainder = AH = 37H (55)
4. doubleword / word
• Numerator must be in AX and DX, least significant word in AX and most significant word
in DX.
• Denominator can be in memory or in a register.
• After the division AX will have the quotient and DX will have the remainder
Ex: DATA1 DD 105432
DATA2 DW 10000
QUOT DW ?
REMAIN DW ?
…..
MOV AX,WORD PTR DATA1 ;AX holds the lower word
MOV DX,WORD PTR DATA1+2 ;DX holds the higher word of the
numerator
DIV DATA2
MOV QUOT,AX ;AX holds the quotient
MOV REMAIN,DX ;DX holds the remainder
5. “Divide Error”: If the denominator is zero (dividing any number by 00) and if the quotient is too
large for the assigned register, “Divide Error” message will be displayed.
LOGIC INSTRUCTIONS
AND
Solution:
35H 00110101
0FH 00001111
05H 00000101 SF=0, ZF=0, PF=1,CF=OF=0
This operation will AND DH with itself and if the result is zero set ZF=1
jumping to NEXT.
OR