Professional Documents
Culture Documents
Assignment 2 Part 2 Solution
Assignment 2 Part 2 Solution
Solution
1. Write a MARIE program that will find the sum of the multiples of 5 between 5 and 500
inclusive, i.e. write a MARIE program to compute and output this sum
5 + 10 + 15 + . . . 495 + 500.
Screenshot:
Explanation:
This program is an implementation of an arithmetic sequence that starts with the number 5 and
ends with the number 500.The program defines four variables: Num1, Sum, Five, and LNum.
Num1 is the variable that holds the current number in the second loop and is initialized to 5. Sum
is the variable that holds the sum of the sequence and is initialized to 5 as well, as the sequence
starts with 5. Five is a variable that holds the value 5, which is the increment added to each
number in the sequence. LNum is a variable that holds the value 500, which is the last number in
the sequence. The program uses two loops. The first loop (Loop1) starts by loading the Num1 into
the accumulator, subtracting LNum from it, and then checking if the result is negative. If the
result is negative, the program jumps to the second loop (Loop2). If the result is not negative, the
program loads the Sum variable into the accumulator and outputs it to the console before
terminating. The second loop (Loop2) starts by loading the current number in the sequence
(Num1) into the accumulator. It then adds Five to the current number, stores the new current
number back into memory, adds the current number to the Sum, stores the updated Sum back into
memory, and then jumps back to the first loop (Loop1) to continue the calculation. This loop
keeps running until the first loop detects that the sum has exceeded the last number in the
sequence.
Q2: Write a MARIE program to display ASCII (American Standard Code for Information
the program
JUMP loop
one, HEX 1
DEC 67 /C
DEC 73 /I
DEC 73 /I
DEC 32 /
space
DEC 40 /(
DEC 65 /A
DEC 109 /m
DEC 101 /e
DEC 114 /r
DEC 105 /i
DEC 99 /c
DEC 97 /a
DEC 110 /n
DEC 32 /
space
DEC 83 /S
DEC 116 /t
DEC 97 /a
DEC 110 /n
DEC 100 /d
DEC 97 /a
DEC 114 /r
DEC 100 /d
DEC 32 /
space
DEC 67 /c
DEC 111 /o
DEC 100 /d
DEC 101 /e
DEC 32 /
space
DEC 102 /f
DEC 111 /o
DEC 114 /r
DEC 32 /
space
DEC 73 /I
DEC 110 /n
DEC 102 /f
DEC 111 /o
DEC 114 /r
DEC 109 /m
DEC 97 /a
DEC 116 /t
DEC 105 /i
DEC 111 /o
DEC 110 /n
DEC 32 /
space
DEC 73 /I
DEC 110 /n
DEC 116 /t
DEC 101 /e
DEC 114 /r
DEC 99 /c
DEC 104 /h
DEC 97 /a
DEC 110 /n
DEC 103 /g
DEC 101 /e
DEC 41 /)
Screenshot:
Explanation:
The program is written in assembly language and is designed to display a message on the
screen. The message is stored in a variable called msg, which contains the ASCII codes for the
characters to be displayed. The character codes are stored in decimal format using the DEC
instruction.
The program starts by defining a label called loop, which is used to loop through the message
character by character. Inside the loop, the program loads the start address of the msg variable
into the accumulator using the LOADI instruction. It then uses the SKIPCOND 400 instruction
to check if the accumulator is zero. If the accumulator is not zero, it jumps to the out label to
display the character on the screen using the OUTPUT instruction. If the accumulator is
The out label starts with the OUTPUT instruction to display the character on the screen. Then,
it loads the msg variable again using the LOAD instruction. It increments the value of msg by
adding the value stored in the one variable (which is the value 1) using the ADD instruction.
The incremented value is then stored back in the msg variable using the STORE instruction.
Finally, it jumps back to the loop label to check if there are more characters to be displayed.
The program continues to loop through the loop and out labels until it reaches the end of the
message, which is indicated by the value 0 stored in the msg variable. The program
increments the value of msg by 1 each time it goes through the loop, which moves to the next
In summary, the program uses a loop to display a message character by character on the
screen. It loads the character codes from a variable, displays them on the screen, increments
the variable to move to the next character, and continues until it reaches the end of the
message.