MP EXP.1
MP EXP.1
MP EXP.1
1
1. Aim: Use of programming tools (Debug/TASM/MASM/8086kit) to perform basic
arithmetic operations on 8-bit/16-bit data.
2. Objective: To understand the programming tools used in assembly language
programming for 8086.
3. Outcomes: The learner will be able to
Write basic programs for 8-bit/16-bit arithmetic operation.
Execute basic commands for assembly language program.
4. Hardware / Software Required: MASM assembler, Text Editor, DOSBOX, Operating
System-Ubuntu/Windows
5. Theory:
.model small
.stack 100h
.data
NUM DB 12H, 34H
SUM DB 2 DUP(0)
.code
START: MOV AX,@data
MOV DS,AX ;Initialize data segment Register
MOV AL,NUM ;First number loaded into AL
MOV AH,0H ;For carry AH register is cleared
ADD AL,NUM+1 ;Second number added with AL
JNC DOWN ;Check for carry
INC BX ;If carry generated increment the AH
DOWN: MOV SUM,AL ;Storing the sum value
MOV SUM+1,AH ;Storing the carry value
INT 3H
END START
ENDS
Output:
ii) Addition of two 16-bit numbers
.model small
.stack 100h
.data
NUM DW 1234H, 0F234H
SUM DW 2 DUP(0)
.code
START: MOV AX,@data
MOV DS,AX ;Initialize data segment Register
MOV AX,NUM ; First number loaded into AX
MOV BX,0H ; For carry BX register is cleared
ADD AX,NUM+2 ; Second number added with AX
JNC DOWN ; Check for carry
INC BX ; If carry generated increment the BX
DOWN: MOV SUM,AX ; Storing the sum value
MOV SUM+2,BX ; Storing the carry value
INT 3H
END START
ENDS
iii) Subtraction of two 8-bit numbers
.model small
.stack 100h
.data
NUM DB 45H, 34H
DIFF DB 2 DUP(0)
.code
START: MOV AX,@data
MOV DS,AX ;Initialize data segment Register
MOV AL,NUM ;First number loaded into AL
MOV AH,0H ;For carry AH register is cleared
SUB AL,NUM+1 ;Second number subtracted from AL
JNC DOWN ;Check for borrow
INC BX ;If borrow generated increment the AH
DOWN: MOV DIFF,AL ;Storing the sum value
MOV DIFF+1,AH ;Storing the carry value
INT 3H
END START
ENDS
iv) Subtraction of two 16-bit numbers
.model small
.stack 100h
.data
NUM DW 1234H, 0234H
SUM DW 2 DUP(0)
.code
START: MOV AX,@data
MOV DS,AX ;Initialize data segment Register
MOV AX,NUM ; First number loaded into AX
MOV BX,0H ; For carry BX register is cleared
ADD AX,NUM+2 ; Second number subtracted from AX
JNC DOWN ;Check for borrow
INC BX ; If borrow generated increment the BX
DOWN: MOV SUM,AX ; Storing the sum value
MOV SUM+2,BX ; Storing the carry value
INT 3H
END START
ENDS
.model small
.stack 100h
.data
NUM DB 12H, 34H
PROD DB 2 DUP(0)
.code
START: MOV AX,@data
MOV DS,AX
LEA SI,NUM ;SI pointed to the Multiplicand
MOV AH, 0 ;clear AH register
MOV AL,[SI] ;Multiplicand has to be in AL register
MOV BL,[SI+1] ;SI+2 pointed to the Multiplier and move it to BL
MUL BL ;Perform the multiplication
MOV PROD,AL ;16 bit product stored in AH-AL registers
MOV PROD+1, AH
INT 3H
END START
ENDS
vi) Multiplication of two 16-bit numbers
.model small
.stack 100h
.data
NUM DW 1234H,1234H
PROD DW 2 DUP(0)
.code
START: MOV AX,@data
MOV DS,AX
LEA SI,NUM ;SI pointed to the Multiplicand
MOV AX,[SI] ;Multiplicand has to be in AX register
MOV BX,[SI+2] ;SI+2 pointed to the Multiplier and move it to BX
MUL BX ;Perform the multiplication
MOV PROD,AX ;32 bit product stored in DX-AX registers
MOV PROD+2,DX
INT 3H
END START
ENDS
.model small
.stack 100h
.data
NUM1 DB 46H
NUM2 DB 11H
QUO DB 1 DUP(0)
REM DB 1 DUP(0)
.code
START: MOV AX,@data
MOV DS,AX
MOV AL,NUM1 ;Move the lower bit of Dividend to AL
MOV AH,00 ; Move the higher bit of Dividend to AH
DIV NUM2 ; Perform the Division operation
MOV QUO,AL ; Store the quotient to AL
MOV REM,AH ; Store the reminder to AH
INT 3H
END START
ENDS
viii) Division of two 16-bit numbers
.model small
.stack 100h
.data
NUM1 DW 2246H
NUM2 DW 1111H
QUO DW 1 DUP(0)
REM DW 1 DUP(0)
.code
START: MOV AX,@data
MOV DS,AX
MOV AX,NUM1 ;Move the lower bit of Dividend to AX
MOV DX,00 ; Move the higher bit of Dividend to DX
DIV NUM2 ; Perform the Division operation
MOV QUO,AX ; Store the quotient to AX
MOV REM,DX ; Store the reminder to DX
INT 3H
END START
ENDS