Micro-Processor and Assembly Language: Lab Assignment#7

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Micro-processor and Assembly Language

Lab Assignment#7
Task 1:
Write an assembly program for 8086 Microprocessor which adds 2 32-bit numbers and stores result in
memory starting with offset address 0001H up to 0005H.

Introduction:
The task is devised into storing 32-bit numbers in memory accessing them through assembly variables
and adding them alongside of carry.

Code

; You may customize this and other start-up templates.

; The location of this template is c:\emu8086\inc\0_com_template.txt

org 100h

.model small

.data

op1 dd 12345678h

op2 dd 11111111h Corel - 10

ans dd ?

.code

mov ax, @data

mov ds, ax

mov ax, word ptr op1 ; lsb of number1 in ax

mov bx, word ptr op1+2 ; msb of number1 in bx

mov cx, word ptr op2 ; lsb of number2 in cx

mov dx, word ptr op2+2 ; msb of number1 in dx

add ax, cx ; add msb + msb + carry


mov word ptr ans, ax ; lsb answer

mov word ptr ans+2, bx ; msb answer

mov bx, word ptr ans+2 ; Result in reg bx

mov dh, 2

l1: mov ch, 04h ; Count of digits to be displayed

mov cl, 04h ; Count to roll by 4 bits

l2: rol bx, cl ; roll bl so that msb comes to lsb

mov dl, bl ; load dl with data to be displayed

and dl, 0fH ; get only lsb

cmp dl, 09 ; check if digit is 0-9 or letter A-F

jbe l4

add dl, 07 ; if letter add 37H else only add 30H

l4: add dl, 30H

mov ah, 02 ; INT 21H (Display character)

int 21H

dec ch ; Decrement Count

jnz l2

dec dh

cmp dh, 0

mov bx, word ptr ans ; display lsb of answer

jnz l1

mov ah, 4ch ; Terminate Program

int 21h

ret
Screenshot

Conclusion
Using carry bits, we can add number of bits

Task 2:
Write an assembly program for 8086 Microprocessor which sorts three 8-bit numbers stored in AL,BL
and CL. Place largest number in AH middle number in BH and smallest in CH register.

Introduction
The program us very straight forward it used cmp (compare statement) and jmp (jump) to compare
numbers and perform required series of actions:

Code
start:

mov ah, 01h

mov bh, 05h

mov ch, 25h

cmp bh, ah

jge notLess

jmp bhGreat

notLess:

cmp ch, bh

jge AllRight

jmp chGreat

bhGreat:

mov bl, ah

mov al, bh

mov ah, al

mov bh, bl

cmp ch, bh

jge AllRight

jmp chGreat:

AllRight:

mov al, ah

mov cl, ch
mov bl, bh

ret

chGreat:

mov bl, ch

mov cl, bh

mov bl, bh

mov bl, ch

jmp AllRight

Screenshot

Conclusion
A deeper understanding of algorithms is required to perform this task how control is shifted through jmp
(jump statements).

Task 3
Write an assembly program for 8086 Microprocessor which calculates Square of 8-bit number stored in
AL if number is ODD and Cube if number is even. 
Introduction

Code
DATA SEGMENT

NO DB 2

DATA ENDS

CODE SEGMENT

SQUARE PROC NEAR

ASSUME CS:CODE

MOV AX,0000

MOV AL,BL

MUL BL

MOV CX,AX

MUL BL

MOV BX,AX

RET

SQUARE ENDP

ASSUME DS:DATA,CS:CODE

START:

MOV AX,DATA

MOV DS,AX

MOV BL,NO

CALL SQUARE

MOV BL,00H

MOV AH,4CH

INT 21H

CODE ENDS
END START

Ret

Screenshot

Conclusion
You can take square or cube of any number by simple multiplication.

You might also like