F20 21 Eeng410 QZ2 Sol

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

St.

Name:

St. No:

EENG410/INFE410 – Microprocessors I
Quiz #2 (04 January 2021)

1.) Write an assembly language program to clear the top 5 rows of the top right quarter of the screen
and display your name at the top right corner of this region. The program further clears the left
bottom quarter and displays the surname in reverse order at the middle of this quarter.

Hints: - INT 10H, AH= 06 scroll up window (clear) with CX to be left top corner and DX to be right bottom corner.
- INT 10H, AH= 02 sets cursor location and assumes row in DH and column in DL.
- INT 21H, AH= 09 displays the string on the screen.
- INT 21H, AH= 02 outputs a character to the monitor. Assumes the character in DL (ASCII)

CLRSCR MACRO LEFTTOP,RIGHTBOTTOM


MOV AX,0600H
MOV BH,07
MOV CX, LEFTTOP
MOV DX, RIGHTBOTTOM
INT 10H
ENDM
DISPSTR MACRO STRING
MOV AH,09
MOV DX,OFFSET STRING
INT 21H
ENDM
SETCURSOR MACRO ROW,COLUMN
MOV BH,00
MOV AH,02
MOV DH,ROW
MOV DL,COLUMN
INT 10H
ENDM
CHARDISP MACRO MYCHAR
MOV AH,02
MOV DL,MYCHAR
INT 21H
ENDM
.MODEL SMALL
.STACK 64H
.DATA
NAME DB ‘ALI$’
SNAME DB ‘VELI’
.CODE
MAIN: MOV AX,@DATA
MOV DS,AX
CLRSCR 0027H,044FH ; row1=0(00H),col1=39(27H): row2=4(04H),col2=79(4FH)
SETCURSOR 00H,4DH ; row=00H (00) , col=4DH (77)
DISPSTR NAME
CLRSCR 0C00H,1827H ; row1=12(0CH),col1=00(00H): row2=24(18H),col2=39(27H)
MOV BL,16H ;(col=22 decimal =16H)
MOV CX,5
MOV SI,OFFSET SNAME
BACK: SETCURSOR 12H,BL ;(row=18 decimal =12H)
MOV AL,[SI]
CHARDISP AL
INC SI
DEC BL ; decrement column provides backward movement
LOOP BACK
MOV AH,4CH
INT 21H
END MAIN

1
2. Given an example of data segment below:

.DATA
X DB +21, -76, +74, -99, -32, -89, -43, -121, +15, -112, +76, -17
S DB 12
P DB ?
N DB ?

Write the definition of a macro which calculates the average of the positive and negative signed
numbers in array X respectively. The macro has 4 arguments. First two arguments are name (X)
and size (S) of the array. Last two arguments are the averages of the positive (P) and negative (N)
signed numbers. The macro ignores the remainders.

MYAVERAGE MACRO X,S,P,N


LOCAL BACK,POSTV,OVER
SUB CH,CH
MOV CL,S
SUB DI,DI
SUB DX,DX
MOV SI,OFFSET X
SUB BX,BX ;make BX=0000H
BACK: MOV AL,[SI]
CBW ;number is extended in AX
ROL AX,1
JNC POSTV
ROR AX,1
ADD BX,AX ;negative accumulator
INC DL ; negative counter
JMP OVER
POSTV: ROR AX,1
ADD DI,AX ;positive accumulator
INC DH ;positive counter
OVER: INC SI
LOOP BACK
MOV AX,BX
IDIV DL ; AX/DL => AL=quoitent, AH=remainder(ignore)
MOV N,AL
MOV AX,DI
IDIV DH ; AX/DH => AL=quoitent, AH=remainder(ignore)
MOV P,AL
ENDM

You might also like