You are on page 1of 6

ITEC1000- Assignment 2

Student Name: Xiangjian Zeng

Student number: 219224211

Part A:

1010100 = 54 16 = E 1101000= 68 16 = Can’t covert( over table limit )=N/A


1101001 = 69 16 = N/A 1110011 = 73 16 = 7
100000 = 20 16 = STX 1101001 = 69 16 = N/A
1110011 = 73 16 = T 1000001 = 41 16 = DC4
1010011 = 53 16 = 5 1011001 = 59 16 = N/A
100001 = 21 16 = DC2

Part B:

Question 1:

Instruction first part:


INP
STA 97
INP
STA 98
INP
STA 99

Comment first part:


/ Input first value
// Store it in memory location 97
// Input second value
// Store it in memory location 98
// Input third value
// Store it in memory location 99

Instruction second part:


LDA 97
SUB 98
BRP 97_GREATER
BRZ 98_EQUAL

Comment for the second part:


// Load value at memory location 97 into the accumulator
// Subtract value at memory location 98
// Branch if positive (97 is greater)
// Branch if zero (97 equals 98)

Instruction for third part:


LDA 97
STA RESULT
BRA COMPARE_WITH_99

// Load value at memory location 97 into the accumulator


// Store the greater value in RESULT
// Branch to compare with the third value

Instruction for fourth part:

97_GREATER LDA 97
STA RESULT
BRA END

// Load value at memory location 97 into the accumulator


// Store the greater value in RESULT
// Branch to the end of the program

Instruction for fifth part:

98_EQUAL LDA 98
SUB 99
BRA COMPARE_WITH_99

// Load value at memory location 98 into the accumulator


// Subtract value at memory location 99
// Branch to compare with the third value

Instruction for six part:

COMPARE_WITH_99 LDA RESULT


SUB 99
BRP RESULT_GREATER

// Load the value in RESULT into the accumulator


// Subtract value at memory location 99
// Branch if positive (RESULT is greater)

Instruction for seven part:


LDA 99
STA RESULT
BRA END

// Load value at memory location 99 into the accumulator


// Store the greater value in RESULT
// Branch to the end of the program

Instruction for eight part:

RESULT_GREATER LDA RESULT


STA RESULT
BRA END

// Load the value in RESULT into the accumulator


// Store the greater value in RESULT
// Branch to the end of the program

END LDA RESULT


OUT
HLT

97 DAT
98 DAT
99 DAT
RESULT DAT

Question 2

LDA 0
STA MAX

Comment:
Load 0 into the accumulator (initialize MAX)
// Store it in MAX memory location

INPUT_LOOP INP
STA VALUE
BRZ END_INPUT

Comment:
Begin the loop to accept input values
// Store the input value in the VALUE memory location
// If the input is 0, go to the end of input
LDA VALUE
SUB MAX
BRZ INPUT_LOOP

Comment:
Load the input value into the accumulator
// Compare with the current MAX value
// If the input value is not greater than MAX, continue the loop

LDA VALUE
STA MAX
BRA INPUT_LOOP

Comment:
Load the input value into the accumulator
// Update MAX if the input value is greater
// Continue looping for further input

END_INPUT LDA MAX


OUT
HLT

Comment:
Load the input value into the accumulator
// Update MAX if the input value is greater
// Continue looping for further input

MAX DAT 0
VALUE DAT

Comment:
Initialize MAX to 0
// Placeholder for input value

Question 3:

LDA 0
//INITIALIZE SUM TO 0
STA SUM
INP
//input the number of values to be added
STA COUNT //store it in count memory location
LOOP BRZ END
//if count is 0, go to the end
INP
ADD SUM
STA SUM
//store the update sum value
SUB ONE
STA COUNT
BRZ END_LOOP
//if count become 0 then go to output
BRA LOOP
// repeat the loop

END_LOOP LDA SUM


OUT
HLT

SUM DAT 0
COUNT DAT
ONE DAT 1

Question 3:

INP // Input value


STA INPUT // Store input value in a variable
LDA INPUT // Load the input value
SUB VALUE // Subtract the value from the calculator
BRZ ZERO_OR_POS // Branch if the result is zero or positive
BRA NEGATIVE // Branch to location 50 if the result is negative

ZERO_OR_POS LDA 0 // Load 0 into the accumulator


OUT // Output 0
HLT // Halt the program

NEGATIVE LDA 1 // Load 1 into the accumulator (any non-zero value)


OUT // Output 1 (to indicate negative result)
HLT // Halt the program

// Data Section
VALUE DAT // Placeholder for the value to be compared
INPUT DAT // Placeholder for the input value

You might also like