Professional Documents
Culture Documents
Assignment
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.
1. Loads AX, BX, CX and DX registers with A154, 7812, 9067, BFD3.
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
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
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] –
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
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
OUT DX, AX
JMP DISPLAY_AND_EXIT
OUT DX, AX
DISPLAY_AND_EXIT:
RET
MAIN PROC
ABC:
ADD AX, 1
JC XYZ
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
MOV CL, 4
SHL AX, CL
MOV CL, 2
SHL BL, CL
MOV DL, BL
SHL BL, 1
ADD BL, DL
INT 21H
MAIN ENDP
END MAIN
FLOW CHART:
START
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 AX, BX
ADC DX, BX
INT 21H
MAIN ENDP
END MAIN