Problem Set 8 Problems 1 – 3 are from chapter 7. Problems 4 – 5 are from chapter 8.
NAME:
1. (5 Points Each) Each of these problems gives “before” conditions and an instruction. Give the indicated “after” state.
Before | Instruction executed | After | |||||
(a) | EBX: FF 00 8E BA | not ebx | 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 | test ax, 80h | AX | ||||
SF __ | ZF__ | ||||||
(e) | AX: 8E BA | shl ax, 4 | AX | ||||
CF __ | |||||||
(f) | AX: 8E BA | sar ax, 4 | AX | ||||
CF __ |
2. (5 Points) 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.
3. (20 Points) Starting with the PROC directive and ending with the ENP directive, write an 80×86 procedure that implements the function described by the following C++ function header:
void arrMix(int arr1[], int arr2[], int arr3[], int count);
// for i=0, 1,…,count-1 bits 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 cdecl protocol.
4. (5 Points Each) 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 repe cmpsb | 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 repne scasb | 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: _____________ |
6. (20 Points) 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
Using 32-bit cdecl protocol, write assembly language code to implement hasLower.