You are on page 1of 14

NAME: HOORAIN SAJJAD

ROLL NUMBER: BM-21020


COURSE TITLE: MICROPROCESSOR
PROGRAMING AND ITS INTERFACING
COURSE CODE: CS-430
COURSE TEACHER: DR. SAAD QASIM KHAN
Third Year; Biomedical Engineering; Fall Semester 2023

Assignment

Attempt any five of the following questions:

1. Write a program that takes two numbers as input and performs their addition. The
code for addition of the numbers should be present in another assembly file that
should be called as a near procedure in the first file.

2. Write a program, which

1. Loads AX, BX, CX and DX registers with A154, 7812, 9067, BFD3.

2. Exchange lower byte of CX and higher byte of DX registers by using

memory location 0150 in between the transfer. Then stores CX and DX

registers onto memory location 0170 onward.

3. Exchange higher byte of AX and higher byte of BX registers by using

memory location 0160 in between the transfer. Then stores AX and BX

registers onto memory location 0174 onward.

4. Also draw the flow chart of the program.

3. Write a program that produces certain delay and then increment the Accumulator
register. When accumulator produces a carry then the buzzer should generate tone
for a certain time. Implement this program using subroutine. The length of delay is
passed to the delay subroutine as a parameter, using stack. Also draw the flowchart.
You can also use any assembler for this exercise.

4. Write a program, which multiply two 8-bit numbers using add and shift logic. Check

the program by

I. loads accumulator with 20H and then multiply it by 10H.

II. loads BL with 10H and multiply it by 12H.


Use any assembler of your choice for this purpose. Also draw the flow chart of the
program.

5. Write a program, which prints your name on the screen when ‘space’ key is pressed

from the keyboard. Implement using conditional jump instruction. Also draw the

flow chart of the program.

6. Write a program, which will add the contents of two 32 bit numbers stored in DX –

AX (DX contains the high order word) and memory location WORD PTR [0202] –

WORD PTR [0200].

7. Write a program, which calculate the factorial of any given number (the number

may be used as an immediate operand in the instruction). Use any assembler for this

exercise.
QUESTION 1
Write a program that takes two numbers as input and performs their addition.
The code for addition of the numbers should be present in another assembly file
that should be called as a near procedure in the first file.
EXTRN A: NEAR
.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB "ENTER FIRST NUMBER: $"
MSG2 DB 0DH, 0AH, "ENTER SECOND NUMBER: $"
.CODE
MAIN PROC
; To move the data defined under .DATA to addresses of actual DS
MOV AX,@DATA
MOV DS, AX
; Display message
LEA DX, MSG1 ; pass offset address of message to DX register
MOV AH, 09H
INT 21H
; User input, which will be stored in AL register in ASCII code
MOV AH, 01H
INT 21H
; Subtract to make the entered number usable in its original value
SUB AL, 48H
MOV BL, AL ; store 1st entered number in variable NUM1
; Display second message
LEA DX, MSG2
MOV AH, 09H
INT 21H
; User input for second operand, which will be stored in AL register in ASCII code
MOV AH, 01H
INT 21H
; Subtract to make the entered number usable in its original with
SUB AL, 48H
MOV BH, AL
CALL A
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Near procedure, containing addition program.
PUBLIC A
.MODEL SMALL
.DATA
MSG DB 0DH, 0AH,"SUM IS: $"
CHAR DB ?,'$'
.CODE
A PROC NEAR
LEA DX, MSG
MOV AH, 09H
INT 21H
ADD BH, BL
ADD BH, 48H
MOV DL, BH
MOV AH, 02H
INT 21H
MOV AH, 4CH
INT 21H
RET
A ENDP
END

QUESTION 2
Write a program, which:
I. Loads AX, BX, CX and DX registers with A154, 7812, 9067, BFD3.
II.Exchange lower byte of CX and higher byte of DX registers by using
memory location 0150 in between the transfer. Then stores CX and DX
registers onto memory location 0170 onward.
III. Exchange higher byte of AX and higher byte of BX registers by using
memory location 0160 in between the transfer. Then stores AX and BX
registers onto memory location 0174 onward.
IV. Also draw the flow chart of the program.
.MODEL SMALL

.STACK 100H

.CODE

MAIN PROC

; (a) load registers with values

MOV AX, A154

MOV BX, 7812

MOV CX, 9067

MOV DX, BFD3

; (b) exchange bytes of registers

MOV SI, 0150H

MOV BYTE PTR [SI], CL


MOV BYTE PTR [SI + 1], DH

MOV DX, BYTE PTR [SI]

MOV CX, BYTE PTR [SI + 1]

; store registers onto memory location

MOV SI, 0170H

MOV WORD PTR [SI], CX

MOV WORD PTR [SI + 1], DX

; (c) exchange bytes of registers

MOV SI, 0160H

MOV BYTE PTR [SI], AH

MOV BYTE PTR [SI + 1], BH

MOV BX, BYTE PTR [SI]

MOV AX, BYTE PTR [SI + 1]

; store registers onto memory location

MOV SI, 0174H

MOV WORD PTR [SI], AX

MOV WORD PTR [SI + 1], BX

; exit DOS and end program

MOV AH, 4CH

INT 21H

MAIN ENDP

END MAIN
FLOW CHART

START

LOAD REGISTERS
AX, BX, CX AND
DX

EXCHANGE BYTES OF CX
AND DX REGISTERS THEN
STORE THEM IN MEMORY
LOCATION 0170 ONWARDS

EXCHANGE BYTES OF AX
AND BX REGISTERS THEN
STORE THEM IN MEMORY
LOCATION 0174 ONWARDS

EXIT
STOP
QUESTION 3
Write a program that produces certain delay and then increment the
Accumulator register. When accumulator produces a carry then the buzzer
should generate tone for a certain time. Implement this program using
subroutine. The length of delay is passed to the delay subroutine as a parameter,
using stack. Also draw the flowchart. You can also use any assembler for this
exercise.

.MODEL SMALL
.STACK 100H
.DATA
DELAY_COUNT EQU 1 ; Adjust the delay count for the desired duration
BUZZER_STATE DB 0 ; 0 - Buzzer off, 1 - Buzzer on
.CODE
DELAY_SUBROUTINE PROC
DELAY_LOOP:
LOOP DELAY_LOOP
RET
DELAY_SUBROUTINE ENDP

TOGGLE_BUZZER PROC
POP CX ; Restore the original CX value
CMP BUZZER_STATE, 0
JE BUZZER_OFF
TOGGLE_BUZZER ENDP

MOV DX, 1046H


MOV AX, 0001H ; Non-zero value for ON

; Adjust port address as needed

OUT DX, AX

MOV AX, 0000H

JMP DISPLAY_AND_EXIT

; Turn off the buzzer


BUZZER_OFF:
MOV DX, 1046H
MOV AX, 0000H ; Zero value for OFF
; Adjust port address as needed

OUT DX, AX

DISPLAY_AND_EXIT:

RET

MAIN PROC

MOV AX, 0FFFAH

ABC:
ADD AX, 1
JC XYZ

; Additional delay before looping


MOV CX, DELAY_COUNT
CALL DELAY_SUBROUTINE
JMP ABC

; Turn on the buzzer


XYZ:
MOV BUZZER_STATE, 1
CALL TOGGLE_BUZZER

; Simulated buzzer tone delay


MOV CX, 1 ; Adjust the count for the desired duration
CALL DELAY_SUBROUTINE

; Turn off the buzzer


MOV BUZZER_STATE, 0
CALL TOGGLE_BUZZER

; Exit DOS and end program


MOV AH, 4CH
INT 21H

MAIN ENDP

END MAIN
FLOW CHART
START

INITIALIZE AX

ABC LOOP

AX += 1

SET CARRY
NOT SET
FLAG

DELAY LOOP

XYZ

TOGGLE
BUZZER IS
BUZZER
OFF

BUZZER IS
ON

EXIT
QUESTION 4:
Write a program, which multiply two 8-bit numbers using add and shift logic.
Check the program by:
I. Loads accumulator with 20H and then multiply it by 10H.
II. Loads BL with 10H and multiply it by 12H.

Use any assembler of your choice for this purpose. Also draw the flow chart of
the program.

.MODEL SMALL

.STACK 100H

.CODE

MAIN PROC

; (a) apply multiply logic using add and shift logics

MOV AX, 20H

MOV CL, 4

SHL AX, CL

; (b) second multiplication

MOV BL, 10H

MOV CL, 2

SHL BL, CL

MOV DL, BL

SHL BL, 1

ADD BL, DL

Exit DOS and end program

MOV AH, 4CH

INT 21H

MAIN ENDP

END MAIN
FLOW CHART:

START

LOAD AX WITH 20H


AND CX WITH 4

MULTIPLY AX BY 10H USING


SHIFT OPERATION AND STORE
RESULT IN AX

LOAD BL WITH 10H


AND CL WITH 2

MULTIPLY BL BY 12H USING


SHIFT AND ADD OPERATIONS
AND STORE RESULT IN BL

EXIT
STOP
QUESTION 6:

Write a program, which will add the contents of two 32 bit numbers stored in DX –
AX (DX contains the high order word) and memory location WORD PTR [0202] –
WORD PTR [0200].

.MODEL SMALL

.STACK 100H

.CODE

.STARTUP

; Add lower bytes

MOV BX, WORD PTR [0200]

ADD AX, BX

MOV BX, WORD PTR [0202]

ADC DX, BX

; Exit DOS and end program

MOV AH, 4CH

INT 21H

MAIN ENDP

END MAIN

You might also like