Reference no: EM132604403
Problem Set
Question 1. Each of these problems gives "before" conditions and an instruction. Give the indicated "after" state.
|
Before
|
Instruction executed
|
After
|
(a)
|
EBX: FF008E BA
|
notebx
|
EBX
|
|
|
|
|
|
|
|
|
|
|
|
|
(b)
|
AX: 8E BA
|
or ax, 0EDF2h
|
AX
|
|
|
|
|
|
|
|
|
SF __
|
ZF__
|
|
|
|
|
|
|
|
|
|
|
(c)
|
AX: 8E BA
|
xor ax, 0EDF2h
|
AX
|
|
|
|
|
|
|
|
|
SF __
|
ZF__
|
|
|
|
|
|
|
|
|
|
|
(d)
|
AX: 8E BA
|
and ax, 0EDF2h
|
AX
|
|
|
|
|
|
|
|
|
SF __
|
ZF__
|
|
|
(d)
|
AX: 8E BA
|
testax, 80h
|
AX
|
|
|
|
|
|
|
|
|
SF __
|
ZF__
|
|
|
(e)
|
AX: 8E BA
|
shl ax, 4
|
AX
|
|
|
|
|
|
|
|
|
CF__
|
|
|
|
|
|
|
|
|
|
|
|
(f)
|
AX: 8E BA
|
sar ax, 4
|
AX
|
|
|
|
|
|
|
|
|
CF__
|
|
|
|
Question 2. Suppose that value is an unsigned integer in the EAX register. Give instructions to compute(value mod 64), putting the result in the EBX register and leaving EAX unchanged.
Question 3. Starting with the PROC directive and ending with the ENP directive, write an 80x86 procedure that implements the function described by the following C++ function header:
voidarrMix(int arr1[], int arr2[], int arr3[], int count);
// for i=0, 1,...,count-1bits 0-7 and 16-23 of arr3[i] come
// from arr1[i] and bits 8-15 and 24-31 come from arr2[i]
Follow 32-bit cdeclprotocol.
Question 4. Each of these problems gives "before" conditions and one or more instructions. Give the indicated "after" state.
|
Before
|
Instruction(s) executed
|
After
|
(a)
|
string1 BYTE "ABCD"
string2 BYTE "GHIJ"
|
cld
lea esi, string1
lea edi, string2
mov ecx, 3
rep movsb
|
ESI
|
|
|
|
|
|
|
|
|
|
|
|
(string1 is at address 00406030 and string2 is at address 00406034)
|
EDI
|
|
|
|
|
|
|
|
|
|
|
|
string1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string2
|
|
|
|
|
|
|
|
|
|
|
|
|
(b)
|
string1 BYTE "BLUE"
string2 BYTE "BEAN"
|
cld
lea esi, string1
lea edi, string2
mov ecx, 4
repecmpsb
|
ECX
|
|
|
|
|
|
|
|
|
|
|
|
(string1 is at address 00406030 and string2 is at address 00406034)
|
ESI
|
|
|
|
|
|
|
|
|
|
|
|
EDI
|
|
|
|
|
|
|
ZF ___
|
|
|
|
|
|
|
|
|
|
|
(c)
|
string BYTE "CSCI"
(string is at address 00406030)
|
cld
lea edi, string
mov al, 'S'
mov ecx, 4
repnescasb
|
ECX
|
|
|
|
|
|
|
|
|
|
|
|
EDI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ZF ___
|
|
|
|
|
|
|
|
|
|
|
|
(d)
|
source: string at address 004BD000: green
dest: string at address 004BD005: crown
|
lea esi,source
lea edi,dest
cld
movsb
|
ESI
|
|
|
|
|
|
|
|
|
|
|
|
EDI
|
|
|
|
|
|
|
string at dest: _____________
|
Question 6. Suppose you want to determine if a string contains all lowercase letters. For this purpose you are going to write a procedure allLower. A C++ header for this procedure might look like
int allLower(char str[]);
// precondition: str is a null terminated string
// postcondition:
// returns true (-1) if str contains only lowercase letters
// returns false (0) if str contains any other character
Using32-bit cdeclprotocol, write assembly language code to implement hasLower.