Reference no: EM132583610 , Length: 6 pages
Problem Set
Question 1. Give the op code and number of bytes of code for each of these instructions.
(a) mov ecx, 984 Op Code______ Number of Bytes _____
(b) xchgeax, ecx Op Code______ Number of Bytes _____
(c) add eax, ecx Op Code______ Number of Bytes _____
(d) add eax, value Op Code______ Number of Bytes _____
(assume value references a doubleword in memory)
(e) incedx Op Code______ Number of Bytes _____
(f) inc DWORD PTR [edx] Op Code______ Number of Bytes _____
(g) neg value Op Code______ Number of Bytes _____
(assume value references a doubleword in memory)
(h) neg edx Op Code______ Number of Bytes _____
(i) neg DWORD PTR [edx] Op Code______ Number of Bytes _____
(j) add ecx, 894 Op Code______ Number of Bytes _____
(k) imuleax, ecx Op Code______ Number of Bytes _____
(l) div value Op Code______ Number of Bytes _____
(assume value references a doubleword in memory)
(m) div DWORD PTR [edx] Op Code______ Number of Bytes _____
(n) cdq Op Code______ Number of Bytes _____
Question 2. Each of these problems gives "before" conditions and an instruction. Give the indicated "after" state of the indicated registers and flags as appropriate.
Before Instruction executed After
(a) ECX: 00 00 BF 7A mov ecx, -89 ECX
(b) ECX: 00 00 BF 7A mov ecx, 984 ECX
(c) EAX: 12 34 56 78
EDX: 9A BC DE F0 xchg ax, dx EAX
EDX
(d) EAX: FF FFFF C8 add eax, 56 EAX
SF __ ZF__ CF__ OF__
(e) EDX: 00 00 02 E9 incedx EDX
SF __ ZF__
(f) EBX: FF FFFF 3B neg ebx EBX
SF __ ZF__
(g) EAX: 01 23 45 67
ECX: 89 AB CD EF sub eax, ecx EAX
SF __ ZF__ CF__ OF__
(h) AX: 12 34
CX: 7A BC
CF:1 adc ax, cx AX
CX
SF __ ZF__ CF__ OF__
(i) EAX: 00 00 00 0A
EBX: FF FFFF FC
EDX: FF 03 FF 01 imulebx EAX
EDX
CF,OF __
(j) EAX: 00 00 00 10
ECX: FF FFFF FD
EDX: FF 03 FF 01 mulecx EAX
EDX
CF,OF __
(k)
EAX: 00 00 00 0A
EBX: 00 00 00 0C
EDX: FF 03 FF 01 imuleax,ebx EAX
EDX
CF,OF __
(l) EAX: 00 00 0E AA
ECX: 00 00 00 1B
EDX: 00 00 00 00 div ecx EAX
EDX
(m) EAX: 00 00 0F CA
EBX: 00 00 00 0D
EDX: 00 00 00 00 idivebx EAX
EDX
Question 3. One way to calculate the harmonic mean of two numbers x and y is using the expression
2xy/(x+y)
Complete the following windows32program to input two numbers and calculate and display their harmonic mean in dddd.dd format. The boxed areas indicate where code is missing.
; student's name here
; program to input two numbers,
; then calculate and display their harmonic mean
; current date here
.586
.MODEL FLAT
INCLUDE io.h ; header file for input/output
.STACK 4096
.DATA
x DWORD ?
y DWORD ?
prompt1 BYTE "First number", 0
prompt2 BYTE "Second number", 0
inArea BYTE 20 DUP (?)
mean BYTE 11 DUP (?), 0
meanLbl BYTE "Harmonic mean", 0
meanOut BYTE 4 DUP(?), '.', 2 DUP (?), 0
.CODE
_MainProc PROC
input prompt1, inArea, 20 ; read ASCII characters
atod inArea ; convert to integer
mov x, eax ; store in memory
; repeat for second number
; calculate 100*(harmonic mean)in EAX
dtoa mean, eax ; convert to ASCII characters
; copy digits, one at a time to meanOut
; output label and mean
mov eax, 0 ; exit with return code 0
ret
_MainProc ENDP
END ; end of source code
Question 4. Starting with the windows32 framework, write a complete program that will input values for a, b and c and display the value of the expression
(a+b*c)/(2*b)
Input and output must be consistent with the samples shown below. Include full source code with comments and screenshots of working program. Expression value can be rounded down to the whole number to avoid fractional outputs. If you are super motivated, challenge youself to print the expression in its more accurate decimal (fractional) format. In the example below, that value would be 8.9 and not 8. That, however, is an optional feature.