Assembly Lab 6 Fall2018
Assembly Lab 6 Fall2018
Objectives:
To understand basic link library functions.
To understand arithmetic instructions in assembly language.
INCLUDE Irvine16.inc
.code
mov ax,1234h ; input argument
call WriteHex ; show hex number
call Crlf ; end of line
call ReadChar
mov char , al
9) ReadInt - Reads an integer from standard input and the returns the integer in AX
register. Example:
.data
var byte ?
.code
call Readint
mov var, ax
10) WriteDec - Writes an unsigned 32-bit integer to standard output in decimal format.
Arithmetic Instructions:
The following table summarizes the arithmetic instructions used in the 8086
microprocessor. It also shows the effect of each instruction, a brief example and the
flags affected by the instruction. The “*” in the table means that the corresponding flag
may change as the result of executing the instruction. The “-“ means that the
corresponding flag is not affected by the instruction, whereas the “?” means that the
flag is undefined after the execution of the instruction.
Addition:
ADD instruction adds a source operand to destination operand of same size. The syntax
is:
ADD destination, source
The source is unchanged by the operation and the sum is stored in the destination
operand.
The carry, zero, Sign, Auxiliary Carry, Parity flags are changed according to the values of
destination operand
Subtraction:
SUB instruction subtracts a source operand from destination operand of same size. The
syntax is:
SUB destination, source
The source is unchanged by the operation and the result is stored in the destination
operand. The CPU performs negation and then addition in order to complete the
subtraction operation.
The carry, zero, Sign, Auxiliary Carry, Parity flags are changed according to the values of
destination operand
Syntax
The syntax for the MUL/IMUL instructions is as follows −
MUL/IMUL multiplier
Multiplicand in both cases will be in an accumulator, depending upon the size of the
multiplicand and the multiplier and the generated product is also stored in two
registers depending upon the size of the operands. Following section explains MUL
instructions with three different cases −
SN Scenarios
The division operation generates two elements - a quotient and aremainder. In case of
multiplication, overflow does not occur because double-length registers are used to
keep the product. However, in case of division, overflow may occur. The processor
generates an interrupt if overflow occurs.
The DIV (Divide) instruction is used for unsigned data and the IDIV (Integer Divide) is
used for signed data.
Syntax
The format for the DIV/IDIV instruction −
DIV/IDIV divisor
The dividend is in an accumulator. Both the instructions can work with 8-bit, 16-bit or
32-bit operands. The operation affects all six status flags. Following section explains
three cases of division with different operand size −
SN Scenarios
Lab tasks
Think of a number (you need to take user input for this number). Double it. Add six.
Divide your answer by two. Now take away the number you first thought of. The
number you get should be... three!