In this assignment you are asked to annotate assembly language code to illustrat
ID: 3604637 • Letter: I
Question
In this assignment you are asked to annotate assembly language code to illustrate that you understand it. Look at the examples in the lecture notes for section 3.4, especially Example 3, and all of Examples 4, 5, and 6. Your comments should indicate what the purpose of the code is in the context of the problem being solved, not just what an individual assembly language instruction does. As an example, in Example 6 from the notes, the line: should not be annotated as: mov! 12 (tebp), %edx // move i into tedx mov! 12 (tebp), %edx // move 4 bytes from memory address %(ebp+12) into %edx Part 1: Create a file called calc.c that contains the following: int calc(int x, int y, int z) return 3*x 2 y 15*2: Compile the program to produce assembly code. Use: cc -01-S calc.c to produce calc.s Copy calc.s into calc.s.txt and annotate calc.s.txt with comments to illustrate that you understand how the calculation is implemented. Make sure you identify each parameter. Print out the annotated code and turin Part 2: Write a main program, testcalc.c, that will test calc.c. The main program should declare three int variables, x, y, and z, and initialize them to 2, 6, and 11, respectively It should then call cale with these parameters and print x, y, z, and the result using the format specification: "X-%d, y-%d, z-ed, result-%d " Before running the program, answer the following question 1) What output should be generated by this program? The program will need a prototype of the function cale. Compile your program with: cc-01-o testcalc testcalc.c calc.sExplanation / Answer
Calculator
PAGE ,132
TITLE CALC
CGROUP GROUP CODESEG
CODESEG SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:CGROUP,DS:CGROUP,ES:CGROUP
PUBLIC CALC
ORG 100H
CALC PROC FAR
JMP START
----------------------------------------------------
DATA AREA
-----------------------------------------------------
DB 'INTERRUPT NUMBER ='
INT_NUMBER DB 61h
SCREEN_HANDLE DW 0001h
MESSAGE DB 'PEMATH is not resident',13,10
MESSAGE_LEN EQU $-MESSAGE
TAG DB 'PEMATH'
TAG_LEN EQU $-TAG
---------------------------------------------------------
CODE AREA
---------------------------------------------------------
START:
----------------------------------------------------------
TEST FOR PRESENCE OF CALCULATOR
----------------------------------------------------------
SUB AX,AX
MOV ES,AX
SUB BH,BH
MOV BL,INT_NUMBER
SHL BX,1
SHL BX,1
MOV DI,ES:[BX]
MOV ES,ES:[BX+2]
ADD DI,4
LEA SI,TAG
MOV CX,TAG_LEN
REPE CMPSB
JE CALL_CALC
MOV BX,SCREEN_HANDLE
MOV CX,MESSAGE_LEN
LEA DX,MESSAGE
MOV AH,40h
INT 21h
JMP SHORT CALC_EXIT
--------------------------------------------------------
CALL CALCULATOR
--------------------------------------------------------
CALL_CALC:
MOV AL,INT_NUMBER
MOV BYTE PTR INT_CODE,AL
DB 0CDh ; INT
INT_CODE:
DB 00h
NOP
NOP
CALC_EXIT:
INT 20h
CALC ENDP
CODESEG ENDS
END CALC