Do you need help with your Assembly Language Homework? Here is the solution to Problem Set 5 homework assignment

1. (2 Points Each) Give the op code and number of bytes of code for each of these instructions.

(a) mov ecx, 984 Op Code______ Number of Bytes _____

The op code and number of bytes for the instruction “mov ecx, 984” depend on the specific assembly language being used and the architecture it targets.

For the x86 architecture, the op code for the “mov” instruction is 0xB9 for moving an immediate value into a 32-bit register like ECX. The number of bytes for this instruction would be 5 bytes.

So, for x86 assembly language:
Op Code: B9
Number of Bytes: 5

(b) xchg eax, ecx Op Code______ Number of Bytes _____

(b) xchg eax, ecx
Op Code: 0x91
Number of Bytes: 1

(c) add eax, ecx Op Code______ Number of Bytes _____

Op Code: 0x01 C8
Number of Bytes: 2

(d) add eax, value Op Code______ Number of Bytes _____

(assume value references a doubleword in memory)

add eax, value (assume value references a doubleword in memory)
Op Code: 0x03 05 (with displacement, the actual address of value)
Number of Bytes: 6

(e) inc edx Op Code______ Number of Bytes _____

(e) inc edx
Op Code: 0xFF C2
Number of Bytes: 2

(f) inc DWORD PTR [edx] Op Code______ Number of Bytes _____

(f) inc DWORD PTR [edx]
Op Code: 0xFF 02
Number of Bytes: 2

(g) neg value Op Code______ Number of Bytes _____

(assume value references a doubleword in memory)

neg value (assume value references a doubleword in memory)
Op Code: 0xF7 1D (with displacement, the actual address of value)
Number of Bytes: 6

(h) neg edx Op Code______ Number of Bytes _____

Get help with your assembly language homework

(i) neg DWORD PTR [edx] Op Code______ Number of Bytes _____

(j) add ecx, 894 Op Code______ Number of Bytes _____

(k) imul eax, 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 _____

2. (3 Points Each) 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 78EDX: 9A BC DE F0 xchg ax, dx EAX EDX (d) EAX: FF FF FF C8 add eax, 56 EAX SF __ ZF__ CF__ OF__ (e) EDX: 00 00 02 E9 inc edx EDX SF __ ZF__ (f) EBX: FF FF FF 3B neg ebx EBX SF __ ZF__ (g) EAX: 01 23 45 67ECX: 89 AB CD EF sub eax, ecx EAX SF __ ZF__ CF__ OF__ (h) AX: 12 34CX: 7A BCCF: 1 adc ax, cx AX CX SF __ ZF__ CF__ OF__
 (i) EAX: 00 00 00 0AEBX: FF FF FF FCEDX: FF 03 FF 01 imul ebx EAX EDX CF,OF __ (j) EAX: 00 00 00 10ECX: FF FF FF FDEDX: FF 03 FF 01 mul ecx EAX EDX CF,OF __ (k) EAX: 00 00 00 0AEBX: 00 00 00 0CEDX: FF 03 FF 01 imul eax,ebx EAX EDX CF,OF __ (l) EAX: 00 00 0E AAECX: 00 00 00 1BEDX: 00 00 00 00 div ecx EAX EDX (m) EAX: 00 00 0F CAEBX: 00 00 00 0DEDX: 00 00 00 00 idiv ebx EAX EDX

3. (13 Points) One way to calculate the harmonic mean of two numbers x and y is using the expression

Complete the following windows32 program 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

3 (continued)

; 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

5. (20 Points) 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

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.    