Uploaded by Khanh Tran

ECE391 Homework 1

advertisement
Ho Chi Minh City University of Technology
Department of Electronics and Electrical Engineering
ECE391: Computer System Engineering
Homework 1
1. For each part of this problem, answer the value of registers after the instruction is
executed.
No.
Before
Instruction
After
1
BX: FF 75
CX: 01 A2
mov bx, cx
BX: ?
CX: ?
2
AX: 01 A2
mov ax, 100
AX: ?
3
EDX: FF 75 4C 2E
Value: DWORD 1
4
AX: 01 4B
5
EBX: 00 00 3A 4C
mov edx, Value
mov ah, 0
mov Value, ebx
Value: DWORD ?
6
EBX: FF FF FF 75
EBX: FF FF FF 75
BX: FF 75
EBX: ?
Value: ?
EBX, ECX, SF, ZF, CF,
OF
sub ebx,ecx
EBX, ECX, SF, ZF, CF,
OF
sub cx,bx
BX, CX, SF, ZF, CF,
OF
ECX: 00 00 01 A2
8
AX: ?
add ebx,ecx
ECX: 00 00 01 A2
7
EDX: ?
Value: ?
CX: 01 A2
9
EAX: 00 00 00 64
sub eax,100
EAX, SF, ZF, CF, OF
10
AX: 0A 20
add ax,Value
AX, SF, ZF, CF, OF
word at Value: FF 20
2. Write a complete 80x86 assembly language program to prompt for values of x, y, and z
and display the value of the expression x*2y + 4z. Allow for 16-bit integer values.
3. Assume for each part of this problem that the EAX register contains 00 00 00 4F and the
doubleword referenced by value contains FF FF FF 38. Determine whether or not each
of the conditional jump statements causes a jump to dest.
(a) cmp eax, value
jl dest
Instructor: Dr. Truong Quang Vinh
Ho Chi Minh City University of Technology
Department of Electronics and Electrical Engineering
(b) cmp eax, value
jb dest
(c) cmp eax, 04fh
je dest
(d) cmp eax, 79
jne dest
(e) cmp value, 0
jbe dest
(f) cmp value, -200
jge dest
(g) add eax, 200
js dest
(h) add value, 200
jz dest
4. Write 80x86 assembly language code for the following C procedure:
int i;
int S=0;
for (i=0;i<10;i++)
{
S = S + i;
}
5. The greatest common divisor (GCD) of two positive integers m and n can be calculated
recursively by the function described below in pseudo code.
function GCD(m, n : integer) : integer;
if n = 0
then
return m;
else
Remainder := m mod n;
return GCD(n, Remainder);
end if;
Implement this recursive definition in assembly language. Use the stack to pass the two
doubleword-size argument values. Return the value of the function in the EAX register. The
procedure should remove the parameters from the stack. Test your function with a main
program that inputs two integers, calls the greatest common divisor function GCD, and displays
the value returned.
Instructor: Dr. Truong Quang Vinh
Download