Lab Manual # 06: The Carry Flag Indicates Whether or Not The Upper Half of The Product Contains Significant Digits
Lab Manual # 06: The Carry Flag Indicates Whether or Not The Upper Half of The Product Contains Significant Digits
MUL
8-bit:
Command MUL BL
AX=AL*BL
Note that the product is stored in a register (or group of registers) twice the size of the operands. The
operand can be a register or a memory operand.
Example 1:
Mov al, 5h
Mov bl, 10h
Mul bl ; AX = 0050h, CF = 0
Example 2:
mov dx,100h
mov ax,2000h
mul dx ; DX:AX = 00200000h, CF=1
*The Carry flag indicates whether or not the upper half of the product contains significant digits.
DIV:
Div CL
AX is divided by CL
8 bit: AX= dividend, divided by contents of any 8-bit register or memory location
After division:
AL= Quotient
AH= Remainder
Example 3:
mov ax,0024h ; dividend
mov cl,0004h ; divisor
div cl ; Ax= 00 09
Example 4:
mov dx,0 ; clear dividend
mov ax,8003h ; dividend
mov cx,100h ; divisor
div cx
Gates:
NOT - Reverse each bit of operand.
NEG - Make operand negative (two's complement).
AND - AND operator gives 1 only if both operands are 1.
Example 5:
mov dx,0 ; clear dividend
mov ax,8003h ; dividend
mov cx,100h ; divisor
JUMP instructions: -
There are two type of JUMP instructions:
1. Unconditional Jumps.
2. Conditional Jumps.
1. Unconditional Jumps: The basic instruction that transfers control to another point in the program is
JMP.
To declare a label in your program, just type its name and add ":" to the end, label can be any character
combination but it cannot start with a number, for example here are 3 legal label definitions: label1: or
label2:
Label can be declared on a separate line or before any other instruction, for example:
x1:
MOV AX, 1
Or
x2: MOV AX, 2
Example 6:
Mov ax, 5 ; set ax to 5.
Mov bx, 2 ; set bx to 2.
jmp calc ; go to 'calc'.
calc:
add ax, bx ; add bx to ax.
Jmp back ; go 'back'.
stop:
2. Conditional jumps:
Unlike JMP instruction that does an unconditional jump, there are instructions that do a conditional
jump (jump only when some conditions are in act). These instructions are divided in three groups,
First group just test single flag
Second compares numbers as signed
Third compares numbers as unsigned
Generally, when it is required to compare numeric values CMP instruction is used (it does the same as
SUB (subtract) instruction, but does not keep the result, just affects the flags).
Or
It's required to compare 7 and 7, 7 - 7 = 0
the result is zero! (Zero Flag is set to 1 and JZ or JE will do the jump).
stop:
Lab Tasks
Task 1:
What will be the hexadecimal values of DX, AX, and the Carry flag after the following instructions
execute?
mov ax,1234h
mov bx,100h
mul bx
Task 2:
What will be the hexadecimal values of DX and AX after the following instructions execute?
mov dx,0087h
mov ax,6000h
mov bx,100h
div bx
Task 3:
Take two binary numbers such as11111111
11111111
Perform two’s complement of the first number and save it to one of the register. Then, reverse the bits
of second binary number and save it to the other register.
1. Take the value 0 in third register and perform the AND operation with both of the results computed
above.
2. Take the value 1 in third register and perform the AND operation with both of the results computed
above.
Task 5:
Division of 8 bit numbers using immediate addressing mode?
Write a code to perform multiplication on 16 bit numbers in consecutive memory locations?
Write a code to add 16 bit numbers and find the average of numbers?
Task 6:
Translate the high-level language assignment statement: A=5×A+12×B
Let A and B be word variables, and suppose there is no overflow.
Task 7:
Try the example no 7 with different numbers for AL and BL, open flags by clicking on flags button, use
single step and see what happens