0% found this document useful (0 votes)
62 views

EEE 105 Lab Exercise 1: Introduction To Assembly Language Programming

The document provides an introduction to an assembly language programming exercise where the student must write a program that takes integers M and N from memory addresses 0x01 and 0x02, calculates the sum of squares from M to N and stores the result in 0x03, and stores a 0x1 or 0x2 in 0x04 depending on if the sum is odd or even. It includes example inputs and outputs to demonstrate the problem.

Uploaded by

Kouji Tomas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

EEE 105 Lab Exercise 1: Introduction To Assembly Language Programming

The document provides an introduction to an assembly language programming exercise where the student must write a program that takes integers M and N from memory addresses 0x01 and 0x02, calculates the sum of squares from M to N and stores the result in 0x03, and stores a 0x1 or 0x2 in 0x04 depending on if the sum is odd or even. It includes example inputs and outputs to demonstrate the problem.

Uploaded by

Kouji Tomas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

EEE 105 Lab Exercise 1

Introduction to Assembly Language Programming

Introduction
For this exercise, you will be creating a program - first, in C-like pseudo code - and then converting it
to assembly language using the provided instruction set in Table 1.
Given integers M and N stored in memory addresses 0x01 and 0x02, respectively, your program should
compute for the sum of the squares of the integers from M to N, inclusive, and the result should be stored
in memory address 0x03. Note that N is greater than or equal to M, and that N and M are always greater
than zero. You should also determine whether the resulting sum is either even or odd. If it is odd, store a
value of 0x1 at memory address 0x04, whereas if the sum is even, store a value of 0x2 at memory address
0x04.
The exercise is worth 15 points.

Instruction set

Table 1: Provided instruction set


Instruction Definition
Copy data from memory at address LOC and write
LOAD REG, LOC
into REG register
Copy data from REG register and write into
STORE REG, LOC
memory at address LOC
Add the contents of registers REG1 and REG2, and
ADD REG1, REG2 store the result into REG1 (REG1 = REG1 +
REG2)
Add the contents of register REG to the signed
ADDI REG, IMM immediate IMM, and store the result into REG
(REG = REG + IMM)
Subtract the contents of register REG2 from REG1,
SUB REG1, REG2 and store the result into REG1 (REG1 = REG1 -
REG2)
Subtract the signed immediate IMM from the
SUBI REG, IMM contents of register REG, and store the result into
REG (REG = REG - IMM)
Execute a bitwise OR between registers REG1 and
OR REG1, REG2
REG2, and store the result into REG1
Execute a bitwise OR between register REG and
ORI REG, IMM
immediate IMM, and store the result into REG
Execute a bitwise AND between registers REG1
AND REG1, REG2
and REG2, and store the result into REG1
Execute a bitwise AND between register REG and
ANDI REG, IMM
immediate IMM, and store the result into REG
Jump execution to LABEL if data in register REG
BLT REG, LABEL
is less than zero
Jump execution to LABEL if data in register REG
BGT REG, LABEL
is greater than zero
Jump execution to LABEL if data in register REG
BEQ REG, LABEL
is equal to zero
JUMP LABEL Jump execution to LABEL unconditionally

1
For this exercise, you may use a maximum of six registers (Reg0 to Reg5). Assume that all registers start
with an initial value of 0. Although an unconditional branch operation (JUMP) is available, try to minimize
/ avoid its usage to minimize the labels in the program for a ’better-looking’ flow.

Example
• Sample input 1: M = 3, N = 10

sum = 32 + 42 + 52 + 62 + 72 + 82 + 92 + 102

sum = 380

• Contents of the memory after performing the computation

Memory Address Stored data (in decimal)


0x01 3
0x02 10
0x03 380
0x04 2

• Sample input 2: M = 50, N = 50


sum = 502
sum = 2500

• Contents of the memory after performing the computation

Memory Address Stored data (in decimal)


0x01 50
0x02 50
0x03 2500
0x04 2

• Sample input 3: M = 5, N = 13
sum = 52 + 62 + ... + 132
sum = 789

• Contents of the memory after performing the computation

Memory Address Stored data (in decimal)


0x01 5
0x02 13
0x03 789
0x04 1

You might also like