1
; 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?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • *Q2: Is the above program logically correct?* Have you tested it for some inputs to see if it at least happens to give the right answer in some cases? If it works, it's a question for https://codereview.stackexchange.com/, if it doesn't then include the test case to make a [mcve]. – Peter Cordes Nov 11 '19 at 15:19

1 Answers1

2

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.

Community
  • 1
  • 1
Erik Eidt
  • 23,049
  • 2
  • 29
  • 53
  • In **A1** will `TIX #99` increment X? If yes, by how much (3 or 1)? In **A3** does it mean that I should change to... `ADD S, #3`, `STA S`, `ADD T, #3`, `STA T` and so on? – Jovial Joe Jayarson Nov 11 '19 at 16:04
  • (1) Yes, TIX increments X, but it only adds 1, so it is good for a for-loop with an i++, for example. (2) while i'm not sure about that code sequence, at the high level: yes, you need to increment by 3 to get to the next word. – Erik Eidt Nov 11 '19 at 16:14
  • One more thing... in (1) if ALPHA+X is the computed address, then it is plausible to say that ALPHA, BETA & GAMMA are assigned different address locations when they were initialized as `LABEL RESW 100`, isn't it? – Jovial Joe Jayarson Nov 12 '19 at 00:06
  • 1
    Yes, exactly. The index X marches forward while the separate instructions access different array's elements using the same index. – Erik Eidt Nov 12 '19 at 00:52