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

Student: Nguyen Le Viet Hoang

ID: 18020574

Chap 5

1. MACRO, ENDM

2. name: WORK_HOUR
body: MOV AL,40 ;WEEKLY HRS
ADD AL,OVRTME_HR ;TOTAL HRS WORKED

dummy argument: OVRTME_HR

4. What is the total value in register DX and AX after invoking the following macro?
WAGES MACRO SALARY, OVERTIME, BONUSES
;TOTAL WAGES = SALARY + OVERTIME + BONUSES
SUB AX, AX ;CLEAR
MOV DX, AX ;AX AND DX
ADD AX, SALARY
ADD AX, OVERTIME
ADC DX, 0 ;TAKE CARE OF CARRY
ADD AX, BONUSES
ADC DX, 0
ENDM
The macro is invoked as
WAGES 60000, 25000, 3000
The total value: 57C1H.
5. In 4., in the body of the macro, dummies were used as they are listed from left to right. Can
they be used in any order? Rewrite the body (leave the dummies alone) by adding OVERTIME
first.
No the order of dummies influences the result of program.
8. Fill in the blanks for the following macro to add an array of bytes. Some blank might not need
to be filled.
SUMMING MACRO COUNT, VALUES
LOCAL AGAIN
;this macro adds an array of byte size alements
;ax will hold the total sum
MOV CX, COUNT ;size of array
MOV SI, OFFSET VALUES ;load offset address of array
SUB AX, AX ;clear ax
AGAIN: ADD AL, [SI]
ADC AH, 0 ;add bytes and takes care of carries
INC SI ;point to next byte
LOOP AGAIN ;continue until finish
ENDM
9. Invoke and run the macro above for the following data
In the data segment:
DATA1 DB 89, 75, 98, 91, 65
SUM1 DW ?
DATA2 DB 86, 69, 99, 14, 93, 99, 54, 39
SUM2 DW ?
DATA3 DB 10 DUP (99)
SUM3 DW ?
SUM1 01A2H
SUM2 0229H
SUM3 03DEH
13. Using INT 33H, write and test an Assembly language program to check the presence of a
mouse in a PC. If a mouse driver is installed, it should state the number of buttons it supports. If
no mouse driver is installed, it should state this.
PRINTSTRING MACRO STRING
MOV AH, 09H
MOV DX, OFFSET STRING
; LEA DX, STRING
INT 21H
PRINTSTRING ENDM
.MODEL SMALL
.STACK 64
.DATA
STR DB 'THIS DEVICE DOESNT SUPPORT MOUSE'
M_BUTTON DW ?
.CODE
MAIN PROC FAR
MOV AX, @DATA
MOV DS, AX
MOV AX,0
INT 33H
CMP AX,0
JE STATE ; EXIT IF DRIVER DOESN'T SUPPORT MOUSE
MOV M_BUTTON,BX ; NUMBER OF BUTTONS
JP EXIT
STATE:
PRINTSTRING STR
EXIT:
MOV AX, 4CH
INT 21H
MAIN ENDP
END MAIN
18. Write an Assembly language program using INT 33H to display the mouse driver version
and number of buttons supported by the mouse in a given PC.
.MODEL SMALL
.STACK 64
.DATA
VERSION DW ?
MS_TYPE DB ?
IRQ DB ?
.CODE
MAIN PROC FAR
MOV AX, @DATA
MOV DS, AX
MOV AX,24H
INT 33H
MOV VERSION, BX
MOV MS_TYPE, CH
MOV IRQ, CL
MOV AX, 4CH
INT 21H
MAIN ENDP
END MAIN
19. Write a C language version of 4.. Your program performs the following.
a. Clear the screen
#include<dos.h>
void main(){
union REGS regin, regout;
regin.x.ax = 0x0600;
regin.h.bh = 0x07;
regin.x.cx = 0;
regin.x.dx = 0x184F;
int86(0x10, &regin, &regout);
}
b. Saves the video mode and changes it to mode hỗ trợ bởi emulator
#include<dos.h>
void main(){
union REGS regin, regout;
regin.x.ax = 0x060D;
int86(0x10, &regin, &regout);
}
c. Gets the mouse pointer position continuously and displays it in the 80x25 character screen
coordinate
#include <stdio.h>
#include<dos.h>
#include<signal.h>
#include<stdlib.h>
#include<unistd.h>
void sighandler() {
printf("Prepare to exit...\n");
exit(0);
}
main() {
signal(SIGINT, sighandler);
unsigned char oldrow;
unsigned char oldcol;
union REGS regin, regout;
while(1) {
//current cursor’s position
regin.h.ah = 3;
regin.h.bh = 0;
int86(0x10, &regin, &regout);
oldrow = regout.h.dh;
oldcol = regout.h.dl;
//move to 80-25
regin.h.ah = 2;
regin.h.bh = 0;
regin.h.dh = 80;
regin.h.dl = 25;
int86(0x10, &regin, &regout);
}
}
d. Upon pressing any key, it restores the original video mode and exits to DOS.
#include <stdio.h>
#include <conio.h>
int main(){
unsigned char oldrow;
unsigned char oldcol;
union REGS regin, regout;
while (!kbhit()){
regin.h.ah = 3;
regin.h.bh = 0;
int86(0x10, &regin, &regout);
oldrow = regout.h.dh;
oldcol = regout.h.dl;
//move to 80-25
regin.h.ah = 2;
regin.h.bh = 0;
regin.h.dh = 80;
regin.h.dl = 25;
int86(0x10, &regin, &regout);
}
char* buff;
regin.h.ah = 0x1C;
regin.h.al = 2;
regin.x.cx = 0;
regin.x.bx = buff;
int86(0x10, &regin, &regout);
return 0;
}
20. Repeat the above problem. This time display the mouse pointer position in pixels. Test it for
video modes AL = 10H and AL = 12H.
#include <stdio.h>
#include <conio.h>
int main(){
unsigned char oldrow;
unsigned char oldcol;
union REGS regin, regout;
regin.h.ah = 0;
regin.h.al = 12; // 16 color graphics (VGA)
int86(0x10, &regin, &reout);
while (!kbhit()){
regin.h.ah = 3;
regin.h.bh = 0;
int86(0x10, &regin, &regout);
oldrow = regout.h.dh;
oldcol = regout.h.dl;
//move to 80-25
regin.h.ah = 0x0C;
regin.h.al = 0x14;
regin.h.bh = 0;
regin.x.cx= 25;
regin.x.dx = 80;
int86(0x10, &regin, &regout);
}
char* buff;
regin.h.ah = 0x1C;
regin.h.al = 2;
regin.x.cx = 0;
regin.x.bx = buff;
int86(0x10, &regin, &regout);
return 0;
}

You might also like