Assembly Language

profileHashim-love1
Q.docx

Assembly Language

CS 245

20 Points

Name ____________________________________

Due: April 02, 2020

1. Each of these problems gives "before" conditions and an instruction. Give the indicated "after" state.

Before

Instruction executed

(a)

ECX: 00 00 BF 7A

mov ecx, -89

(b)

ECX: 00 00 BF 7A

mov ecx, 984

(c)

EAX: 12 34 56 78

EDX: 9A BC DE F0

xchg ax, dx

(d)

EAX: FF FF FF C8

add eax, 56

ZF__

CF__

OF__

(e)

EDX: 00 00 02 E9

inc edx

ZF__

(f)

EBX: FF FF FF 3B

neg ebx

ZF__

(g)

EAX: 01 23 45 67

ECX: 89 AB CD EF

sub eax, ecx

ZF__

CF__

OF__

(h)

EAX: 00 CC 00 10

ECX: FF FF AF FD

EDX: FF 03 FF 01

mul ecx

EAX

EDX

CF,OF __

(i)

EAX: 00 CC 00 0A

EBX: 00 AA 00 0C

EDX: FF 03 FF 01

imul eax,ebx

EAX

EDX

(i)

EAX: 00 CC 00 0A

EBX: 00 AA 00 0C

EDX: FF 03 FF 01

div ebx

EAX

EDX

2. 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. Supply appropriate code in the boxed areas.

.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 (Complete the missing lines)

mov al, mean+5

mov meanout, al

mov al, mean+6

mov meanout+1, al

mov al, mean+7

mov meanout+2, al

; 1st digit

; 2nd digit

; 3rd digit

; output label and mean

mov eax, 0 ; exit with return code 0

ret

_MainProc ENDP

END ; end of source code