# Data Definitions, Addressing Modes, Arrays Solution

[Memory Map] Fill in the following memory diagram with the data provided below. Please assume that the data segment begins at 0x00404000.

.data

Alpha       WORD        33h, 24h

Beta       BYTE        67h

Gamma       DWORD       5677h

Delta       BYTE        33h

Variable
Data
00404000

00404001

00404002

00404003

00404004

00404005

00404006

00404007

00404008

00404009

[Addressing Modes] Copy the following code into your assembly development environment and single-step through it.  For those instructions referencing memory, write the linear address.

INCLUDE Irvine32.inc

.data

alpha       DWORD       44h, 23h

beta       DWORD       6788h, 66h

gamma       DWORD       1234h

.code

main PROC

mov eax, 12h;                 Immediate

mov ecx, eax;                 Register to Register

mov edi, OFFSET beta;         Immediate

mov [gamma], eax;             Indirect

mov esi, [gamma];             Direct

mov esi, 4;                   Immediate

mov eax, beta[esi];           Indirect-offset

mov ebx, OFFSET alpha;        Immediate

mov eax, [ebx];               Indirect

mov eax, 4[ebx];              Indirect-displacement

mov eax, 4[ebx][esi];        Base-Indirect-displacement

exit

main ENDP

END main

[Indirect addressing] Write a program that adds a constant value to each element of an array and places the value in the ModArray.   Use:

.data

Array       WORD 23h, 45h, 45h, 56h, 25h, 44h, 22h, 54h, 12h

ConstVal    WORD 20h

ModArray    WORD 9 DUP (?)

[Loops] Write a program to compute the sum of first n even integers.  Sum = 2 + 4 + 6 … + n.  Your program must:

Prompt user for integer n,
Read the value of n from user input
Calculate Sum, and;
Print Sum on screen.

Please use the “WriteInt” procedure, not “DumpRegs”. Other relevant procedures: “ReadInt” and “WriteString.” The calculation can be done in many ways, and all submissions that evidence proper programming practice are acceptable. In your homework submission, please embed both the code and one screen shot for n = 60.  You can assume that the user is considerate and careful and thus only inputs even values for n.