Sample Homework Assignment #2


Overview

This is a sample assignment, which is exactly like all the practice problems posted in this module. Just in case you wanted more practice, here you go. Some of the numbers in there care large-ish, and a calculator may be useful. In exams/quizzes numbers will be small and a calculator is not needed.

Solutions

Solutions are available as a plain ASCII file.


Exercise #1: Memory Layout

Consider the following .data segment:

A       dd      011111b
B       dw      -27, -1
C       dd      -34o
D       db      "a", 0, "z", 27o
E       db      043h, 00b, 0AAh
F       dw      043AAh

Question #1 [18pts]

Show the contents of the memory bytes starting at address A, in hex, on a machine that uses Little Endian. Indicate labels as well. For instance, a (wrong) answer could look like:

A     B     C  ...
FF FF FA 02 03 06 ...

Question #2:

For each of the 6 labels, indicate whether it would lead to a different in-memory byte order on a Big Endian machine.


Exercise #2: Memory and Registers

Consider the following .data segment:

L1       L2       L3       L4       L5
3A FF 01 02 FF 6B B2 AA 42 41 61 62 D3 D5 D7

and the following program fragment:

mov	eax, L3
mov	ebx, L5
mov	ecx, 0
mov	cl, [L2]
sub     ebx, ecx
mov     ebx, [ebx]
add     eax, 2
mov     ecx, [eax]
mov     [L4], cx
mov     ax, [L1]
add     bx, ax
mov     [L1], ebx

After the code finishes executing, what are the contents of the 15 memory bytes starting at address L1, on a machine using Little Endian?

Here is the way to show your work for each instruction:

For instance, a partial answer (for a different program) could look like:

L1       L2       L3       L4       L5
3A FF 01 02 FF 6B B2 AA 42 41 61 62 D3 D5 D7

mov	ebx, L1 	; ebx = address of the 1st byte

mov	ecx, 0		; ecx = 00 00 00 00

mov	cx, [L3]	; ecx = 00 00 AA B2

mov	[L2], ecx	; updates memory state:

L1       L2       L3       L4       L5
3A FF 01 B2 AA 00 00 AA 42 41 61 62 D3 D5 D7

mov	ebx, L4		; ebx = address of the byte with value 41

mov 	bx, 12		; ebx = ?? ?? 00 0C

...