CSC231 Midterm Solution 2017
--D. Thiebaut (talk) 17:32, 27 October 2017 (EDT)
- Problem 1
One
- Problem 2
abc 1 abc 2 abc 3
- Problem 3
11111111
11110000
0xAABB + 0x7733 = 0x121EE
- Problem 4
mov bl, dx ; operands must be the same size neg ax, bx ; neg takes only one operand xor dword[x2],dword[x] ; no memory to memory operation allowed
- Problem 5
A dw 0x0100 B db 0x12 C dw 0xBBAA D db 0xCC E dd 0x11FFEEDD
- Problem 6
A dw 0x00FF B db '0' C dw 10*256+10 ; or 0x0A0A D db 0xFF E dd 0x04FF0201
- Problem 7
- eax: 0x00000000
- ebx: 0xFFFFFFFFF
- ecx: 0xFF0055AA
- edx: 0x0000FF00
- Problem 8
- eax: 0000 0000 0000 0000 0000 0000 1111 1111
- ebx: 1111 1111 1111 1111 0000 0000 0000 0000
- ecx: 0xFFFFFFFE
- edx: 0
- Problem 9
i is an int. It starts at 0 and reaches the value 0x7FFFFFFF which is the largest positive number in a 2's complement format. Then it becomes 0x80000000 which is negative. So the loop goes 0x7FFFFFFF which is approximately 2 billion.
x is an int. It starts with value 1. or 0000000000000000000000000000001.
After the first loop it is 2. or 0000000000000000000000000000010.
After the third loop, it is 4, or 0000000000000000000000000000100
And it continues, 8, 16, 32, 64. Every time the 1 bit shifts to the left by 1. Since there are 32 positions for this bit to be, after 32 loops it will have moved out of the 32-bit word, and x will be 0.
True, x will be 0 after 256 loops.
- Problem 10
mov ax, word[a] add ax, word[b] add ax, ax sub ax, word[c] mov word[sum], ax
- Problem 9b
0 0 0 1 <-- e -1 -1 -1 <-- d 'B' 'A' <-- c 00 FF <-- b 00 00 00 'A' <-- a
- approximately 2 billion times
- Problem 11
- 0 to 255
- -128 to 127