; Assembly Program
;¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|¯¯¯|
; |
; Programmer: joe247 |
; |
;___|___|___|___|___|___|___|___|___|
; Write a SIC/XE Program program in which ALHPA, BETA and GAMMA are array capable of storing 100 words.
; Add the words in ALPHA and BETA and store it in GAMMA.
; Assumption 1: that the data is already stored in the corresponding locations ALPHA & BETA
; Assumption 2: the memory is a linear array starting from 0
;
; Memory Locations:
; ______ ______ ______ ______ ______ ______ ______ ______ ______
; | 0000 | 0001 | 0002 |...| 0100 | 0101 | 0102 |...| 0200 | 0201 | 0202 |...
; ¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯
; X S T
;LABEL OPCODE OPERAND
;----- ------ -------
LDX #0 ; X = 0
LDS #100 ; S = 100
LDT #200 ; T = 100
LOOP LDA ALPHA, X ; A = ALPHA[X]
ADD BETA, S ; A += BETA[T]
STA GAMMA, T ; GAMMA[T] = A
ADD S, #1 ; A = S + 1
STA S ; S = A
ADD T, #1 ; A = T + 1
STA T ; T = A
TIX #99 ; check if X <= 99: set flag & X += 1
JLT LOOP ; jump to LOOP if flag is set
;-----------------------------------------------------------------------------
ALPHA RESW 100 ; reserve 100 words for ALPHA
BETA RESW 100 ; reserve 100 words for BETA
GAMMA RESW 100 ; reserve 100 words for GAMMA
Q1: Is the second assumption correct with respect to an SIC/XE machine?
Q2: Is the above program logically correct?
Q3: The code given in page 16 of this: https://drive.google.com/file/d/1-Mt59wikepLm8_Bc-eDK8LGKjqQn7lSQ/view?usp=sharing PDF does the same, but I loose the flow of execution... why is there THREE, 300 and all?
Here is the code from the PDF:
; SIC/XE
; ======
LDS #3 ; INITIALIZE REGISTER S TO 3
LDT #300 ; INITIALIZE REGISTER T TO 300
LDX #0 ; INITIALIZE INDEX RESISTER TO 0
ADDLP LDA ALPHA, X ; LOAD WORD FROM ALPHA INTO REGISTER A
ADD BETA, X ; ADD WORD FROM BETA
STA GAMMA, X ; STORE THE RESULT IN A WORD IN GAMMA
ADDR S, X ; ADD 3 TO INDEX VALUE
COMPR X, T ; COMPARE NEW INDEX VALUE TO 300
JLT ADDLP ; LOOP IF INDEX VALUE IS LESS THAN 300
.
.
. ; ARRAY VARIABLES --100 WORDS EACH
ALPHA RESW 100
BETA RESW 100
GAMMA RESW 100
I don't understand how these work: LDA ALPHA, X
, COMPR X, T
and TIX #99
?
I don't understand how these work: LDA ALPHA, X, COMPR X, T and TIX #99?
LDA ALPHA, X
—
This instruction computes the address ALPHA + X and loads the word (3 bytes) at that address into the A register.
COMPR X, T
—
This instruction compares the X register's value with the T register's value, setting the condition codes in the SW (status word register) with the result of the comparison.
TIX #99
—
This instruction compares the X register's value with an immediate value 99, and also sets the condition codes in the SW register with the result of the comparison.
the memory is a linear array starting from 0
Is the second assumption correct with respect to an SIC/XE machine?
The memory is indeed a linear array, though where it starts is somewhat irrelevant, because labels abstract the actual locations.
Is the above program logically correct?
No, your program is mixing byte-arithmetic address computations with word loading, and it should be using word-arithmetic address computations with word loading.
Since words are 3 bytes long, you have to add 3 to your indexes to get to the next word. That is also why an array of 100 words (3-byte elements) stops after 300 bytes.