Compilation of Programs in C
Analyze the following C procedure to determine
how the C compiler would generate the assembly code
for the following function. Assume that the size of
an int is 16 bits, the size of a long is 32 bits,
and that all procedures are far calls.
#define SAFE_DISTANCE 7
/* Assume CS:IP at this location is 5558:1288h */
ComputeTrajectory(int Xpos, int YPos, int Zpos) {
int i=1;
long Distance=0x33112200;
/* Assume CS:IP at this location is 5558:1986h */
[breakpoint]
..
return(Distance+Xpos+YPos)
}
main() {
int EnemyXPos = 0x0060;
int EnemyYPos = 0x1998;
/* Assume CS:IP at this location is 6764:1987h */
ComputeTrajectory(EnemyXPos+SAFE_DISTANCE, EnemyYPos, 0x4120);
/* Assume CS:IP at this location is 6764:2002h */
}
At the [breakpoint], determine the following
byte-sized values. Specify your results in hex ).
If a value is undefined, enter 'XXXX'
[BP ]= (hex) (2 pts)
[BP+2 ]= (hex) (2 pts)
[BP+4 ]= (hex) (2 pts)
[BP+6 ]= (hex) (2 pts)
[BP+8 ]= (hex) (2 pts)
[BP+10]= (hex) (2 pts)
[BP-2 ]= (hex) (2 pts)
[BP-4 ]= (hex) (2 pts)
[BP-6 ]= (hex) (2 pts)
[SP ]= (hex) (2 pts)
[SP+2 ]= (hex) (2 pts)
[SP-2 ]= (hex) (2 pts)
Text-Mode Video
For each of the elements that we wish to display on an 80x25 text-mode
screen, determine the attribute (AH), character (AL), and offset (DI)
into video memory that must be established before we execute the
following code: Specify all numbers in hex.
MOV DX, 0B800h
MOV ES, DX
MOV ES:[DI],AX
The letter 'J' in blue on a black background at row 0, column 3.
AX= (2 pts)
DI= (2 pt)
The letter 'L' in (intense) white on a green background
at row 3, column 3.
AX= (2 pts)
DI= (2 pt)
A magenta (purple) heart on a black background at row 10, column 54.
AX= (2 pts)
DI= (2 pt)
An intensely-colored green clover on a black background on the third
text-mode video page (page 2) at row 2, column 3.
AX= (2 pts)
DI= (2 pt)
A blinking, empty, black, smiley character on a purple
(red+blue) background on the fourth text-mode video page (page 3),
at the lower-righthand corner of the screen.
AX= (2 pts)
DI= (1 pt)
Jump Tables
Consider the following code that uses a jump
table to recursively call itself. Find the values of Result after
calling the Main program. Calculate the five elements of
Result[] in decimal (base 10). All variables are to be considered
signed integers.
Result db 5 dup(11)
..start:
XOR CX,CX
MLoop: MOV SI,CX
MOV DI,CX
SHL DI,1
Call [JTable+DI]
INC CX
CMP CX,5
JB MLoop
Call dosxit ; End of main program
JTable dw F0
dw F1 ; The comments in the homework
dw F2 ; are never very helpful.
dw F3
dw F4
dw F5
JFunct:
; The following code is for demonstration purposes only.
; Coding MPs using this style can be hazardous
; to your mental health.
F0: ROR [Result+SI],1
SAR [Result+SI],1
RET
F1: SHR [Result+SI],1
RET
F2: AND [Result+SI],1
Call JFunct
ADD [Result+SI],65
RET
F3: SHL [Result+SI],1
JMP [JTable+DI-4]
F4: XOR [Result+SI],63
RET
F5: ADD [Result+SI],40
RET
Result[0]= (decimal) (2 pts)
Result[1]= (decimal) (2 pts)
Result[2]= (decimal) (2 pts)
Result[3]= (decimal) (2 pts)
Result[4]= (decimal) (2 pts)
DOS/BIOS/vBIOS Calls
The BIOS (Basic I/O System), vBIOS (Video BIOS), and DOS provide a number
of useful functions available through interrupt vectors. To use these
commands, the opcode INT n is used to trigger the software interrupt.
Using your lab manual, textbook, or lecture notes; determine what values
are necessary to perform the following actions. Specify all
numbers in hex.
DOS function to get the system time.
INT (hex)
(2 pts)
AH = (hex)
(2 pts)
Mouse function to set horizontal min/max position.
INT (hex)
(2 pts)
AX = (hex)
(2 pts)
DOS function to write to a file or device using handle.
Hint: See Interrupt list in HELPPC section of class-resources
or try MASM /H
INT (hex)
(2 pts)
AH = (hex)
(2 pts)
VIDEO BIOS function to read cursor position and size.
INT (hex)
(2 pts)
AH = (hex)
(2 pts)
Hardware Interrupt vector number called when a SCSI device generates
an interrupt on IRQ 10d.
INT (hex)
(2 pts)
Hardware Interrupt vector number called for a IRQ4 generated interrupt.
INT (hex)
(2 pts)
Hardware Interrupt vector number called when your IDE disk controller
on the lowest-priority IRQ generates an interrupt.
INT (hex)
(2 pts)