I'm doing this for a school assignment I've been given in Computer Architecture. The topic is on the Von Neuman Machine (The IAS) and we were tasked to create a program that can do whatever we wanted.
I opted for a program that could Check someone's temperature and determine whether it was normal, if they have a fever or hypothermia...Just something simple.
I keep getting the error whenever I try to load the code into the IAS simulator, "Labels can only be used with instructions in the left half of a word at line 8 and column 0." It has given me a headache and I do not know what to do. Please help me.
This is the code:
; Program
_pgm0: ; Average temperature
S(x)->Ac+ _temp1
S(x)->Ah- _temp2
R ; Divide by 2
At->S(x) _avg_temp
Cu->S(x) _pgm1 ; Continue to hypothermia check
_pgm1: ; Hypothermia check
S(x)->Ac+ _avg_temp
S(x)->Ah- _hypo_thresh
Cc->S(x) _pgm2 ; If >= hypothermia threshold, check for low
S(x)->Ac+ _severe_hypo
At->S(x) _hypo_grade
Cu->S(x) _halt_addr
_pgm2: ; Basic low temperature check
S(x)->Ac+ _avg_temp
S(x)->Ah- _low
Cc->S(x) _pgm3 ; If >= low threshold, check for fever
S(x)->Ac+ _toolow
At->S(x) _alert
Cu->S(x) _halt_addr
_pgm3: ; Fever check
S(x)->Ac+ _avg_temp
S(x)->Ah- _high
Cc'->S(x) _normal ; If < high threshold, it's normal
S(x)->Ac+ _toohigh
At->S(x) _alert
Cu->S(x) _halt_addr
_normal: ; Normal temperature
S(x)->Ac+ 0
At->S(x) _alert
Cu->S(x) _halt_addr
; DATA
; Temperature Inputs
_temp1:.data 370 ; First input temperature (e.g. 37.0)
_temp2:.data 380 ; Second input temperature (e.g. 38.0)
; Thresholds (scaled by 10)
_hypo_thresh:.data 355 ; Hypothermia threshold (35.5)
_low:.data 360 ; Low threshold (36.0)
_high:.data 380 ; High threshold (38.0)
; Alert Codes
_toolow:.data 1 ; "Too low" alert code
_toohigh:.data 2 ; "Too high" alert code
_severe_hypo:.data 2 ; Severe hypothermia code
_normal_code:.data 0 ; Normal temperature code
; Output Variables
_avg_temp:.data 0 ; Calculated average temperature
_alert:.data 0 ; 0 = normal, 1 = too low, 2 = fever
_hypo_grade:.data 0 ; 0 = none, 2 = severe hypothermia
; Control
_halt_addr:.data 9 ; Halt loop address
I tried re-formatting some lines and moving them closer to the left but that did not seem to work as well.
I also tried changing the way I structured the Data below but that did not seem to get it running.
Locations/words are 40 bits wide, while instructions are 20 bits wide. Thus, instructions are packed 2 per location/word, and then referred to as a left half and a right half at that location/word. Yet, in assembly language, for what appears to be an instruction stream, every two successive instructions are packed into a single location/word.
So, in your code:
S(x)->Ac+ _temp1
S(x)->Ah- _temp2
are in the first location/word, while
R ; Divide by 2
At->S(x) _avg_temp
are in the next location/word, and,
Cu->S(x) _pgm1 ; Continue to hypothermia check
_pgm1: ; Hypothermia check
S(x)->Ac+ _avg_temp
fill out the next location/word with those two instructions.
This means that the label _pgm1
refers to the instruction in the right half of the location/word.
The Cu->S(x)
instruction requires a label to identify the location/word to target, but it can only branch to the left half instruction of the word.
There are several solutions — you can:
Cu->S(x) _pgm1
(such as extra line of R
). That will fill out the right half of the location/word, which will bring the label _pgm1
to the position of the left half instruction of the next sequential location/word.Cu`->S(x)
, which will transfer control to the right half instruction of the location/word.Cu`->S(x)
.Due to the error messages, cannot get as far as to load this assembly code, which is too bad, because once these error are fixed (or you start exploring with some known good code) you can visualize in the "RAM Selectrons" view how the instructions have been packed two per location/word.
This window has an option to show 40 bits per line of disassembly (default) or 20 bits. You can see that when using 20 bits per line, the instructions are each on their own line; however, the addresses repeat (two rows/lines for address 0, two for address 1, etc..).