Lab 5, 6 and 7 Exercises

advertisement
Lab 5, 6 and 7 Exercises
1.
Calculate the following assignment statement in emu.
RESULT = A*5 / B*2 + 3
Where A = 4 and B = 2 , show the result on screen.
org 100h
;MULTIPLY A*5 AND SAVE IT IN RES
MOV AL,5
MUL A
MOV RES,AX
;CLEAR AX FOR NEXT MULTIPLICATION
XOR AX,AX
;MULTIPLY B*2
MOV AL,2
MUL B
;SAVE THE RESULT IN BX FOR NEXT DIVISION
MOV BX,AX
;DIVIDE A*5/B*2
MOV AX,RES
CWD
DIV BX
;SAVE THE RESULT IN RES
MOV RES,AX
;ADD RES+3
ADD RES,3
;MOVE RES TO CX TO DISPLAY THE RESULT IN REGISTER
MOV CX,RES
ret
A DB 4
B DB 2
RES DW ?
2. Let the user input 2 numbers and display the result of multiplication.
org 100h
;INPUT FIRST NUMBER
CALL INDEC
;SAVE IT IN BX
MOV BX,AX
;DISPLAY A NEWLINE
CALL NEWL
;CLEAR AX FOR NEXT NUMBER
XOR AX,AX
;INPUT SECOND NUMBER
CALL INDEC
;MULTIPLY THE ENTERED NUMBERS
MUL BX
;CLEAR BX AND MOVE THE RESULT TO BX TO BE SAVED
XOR BX,BX
MOV BX,AX
;DISPLAY A NEWLINE
CALL NEWL
;MOVE THE RESULT TO AX AND CALL OUTDEC TO DISPLAY THE RESULT
MOV AX,BX
CALL OUTDEC
ret
NL DB 0DH,0AH,"$"
NEWL PROC
MOV AH,9
LEA DX,NL
INT 21H
RET
NEWL ENDP
INCLUDE PGM9_1.ASM
INCLUDE PGM9_3.ASM
END
3. Enter a word or a sentence and save it in an array, then print this word or sentence in a
newline.
org 100h
;CLEAR CX FOR COUNTER
XOR CX,CX
;LOAD THE ARRAY
LEA SI,ARR
MOV AH,1
;BEGIN READING CHARACTERS FROM USER UNTIL SHE PRESS ENTER
ENT:
INT 21H
CMP AL,0DH ;CHECK IF THE CHARACTER ENTERED IS CR
JE PREP
MOV [SI],AL ;MOVE CHARACTER TO ELMENT IN ARR
INC SI ;INCREMENT TO GO TO NEXT ELEMENT
INC CX ;INCREMENT TO COUNT NUMBER OF CHARACTERS ENTERED
JMP ENT
PREP:
MOV AH,9 ;DISPLAY A NEWLINE
LEA DX,NL
INT 21H
LEA SI,ARR ;LOAD THE FIRST CARACTER TO BE DISPALYED
MOV AH,2
;BEGIN PRINTING THE CHARACTER ENTERED IN A NEWLINE
DISP:
MOV DL,[SI]
INT 21H
INC SI
LOOP DISP
ret
NL DB 0DH,0AH,"$"
ARR DB 7 DUP (?)
Download