IBM 650 machine pseudocode


Each pseudocode instruction is in the form of a signed ten digit decimal integer. The integers are stored in the form

±wxxxyyyzzz

but for readability, we can choose to display them in the form

±w xxx yyy zzz

where w represents the operation (20 possibilities, if the sign is considered), xxx represents the first three digit (address) operand, yyy the second operand, and zzz the destination.
sign op xxx yyy zzz (destination)
Code
+
-
comments
0
move
?
x => z ?
1 add subtract (x + y) => z (x - y) => z
2 multiply divide ( x*y) => z (x ÷ y) => z
3 square square root (x *x) => z sqrt(x) => z
4 <> if x = y, jumpto z if x <> y, jumpto z
5 >= < if x >= y jumpto z if x <y, jumpto z
6 array operation 
x[@y] => z
array operation 
x => y[@z]
move data from array move data to array
7 loop operation 
incr and test
label a program address incr(x), loop to z if incr(x) <= y -7 0LL 000 000
8 read print read a card value into z print a card from value in x
9 stop (unused)

NOTES ON PSEUDO-CODE

overview
For any operation for which not all of the fields xxx, yyy, or zzz are used, it is mandatory that the entries not used be set at 000



move (+0)
(a) The operation +0 will move the contents of data location xxx to to data location zzz
NOTE: yyy must be set at 000
example
+0 123 000 456 moves the contents of data location 123 to data location 456


addition/subtraction (+1, -1)
(a) The operation +1 will sum the contents of data location xxx with the contents of data location yyy, and will store the result in data location zzz
(b)The operation +-1 will form the difference betweenthe contents of data location xxx and the contents of data location yyy, and will store the result in data location zzz
examplee
+1 123 456 789 adds the contents of data location 123 to data location 456 and stores the result in data location 789
-1 123 456 789 subtracts the contents of data location 456 from the contents of data location 123 and stores the result in data location 789


multiplication/division (+2, -2)
(a) The operation +2 will multiply the contents of data location xxx with the contents of data location yyy, and will store the result in data location zzz
(b)The operation +2 will divide the contents of data location xxx by the contents of data location yyy, and will store the result in data location zzz
example
+2 123 456 789 multiplies the contents of data location 123 by the contents of data location 456 and stores the result in data location 789
-2 123 456 789 divides the contents of data location 123 by the contents of data location 456 and stores the result in data location 789


square/square root (+3, -3)
(a) The operation +3 will calculate the square the contents of data location xxx, and will store the result in data location zzz.
(b)The operation -3 will calculate the square root of the contents of data loc xxx, and will store the result in data loc zzz.
NOTE: yyy must be set at 000
example
+3 123 000 456 squares the contents of data location 123 and stores the result in data location 456
-3 123 000 456 takes the square root of the contents of data location 123 and stores the result in data location 456


comparisons (+4, -4, +5, -5)
(a) The operation +4 will compare the contents of data locations xxx and yyy, and will jumpto program location zzz if the two items compared are equal.
(b) The operation -4 will compare the contents of data locations xxx and yyy, and will jumpto program location zzz if the two items compared are unequal.
(c) The operation +5 will compare the contents of data locations xxx and yyy, and will jumpto program location zzz if the contents of xxx is greater than or equal to the contents of yyy
(d) The operation -5 will compare the contents of data locations xxx and yyy, and will jumpto program location zzz if the contents of xxx is less than the contents of yyy.
example
+4 123 456 789 ;compare the contents of data locations 123 and 456 and if they are equal, jump to prog location 789
-4 123 456 789 ;compare the contents of data locations 123 and 456 and if they are unequal, jump to prog location 789
+5 123 456 789 ;compare the contents of data locations 123 and 456 and if the contents of data location 123 is greater than or equal to the contents of data locations 456, jump to prog location 789
-5 123 456 789 ;compare the contents of data locations 123 and 456 and if the contents of data location 123 is less than the contents of data location 456, jump to prog location 789


arrays (+6, -6)
Arrays elements are defined by the starting address in data memory) of the array and the offset (index) of the item.
NOTATION
If the starting address (data memory) of the array is x= xxx, and the value of the index is stored in (data memory) location y= yyy, then we will use the notation @yyy to represent the contents of address yyy, and x[@y] for the contents of the data address xxx+@yyy, (where @yyy refers to the contents of address yyy, and xxx refers to the address of the start of the array)
(a) The operation +6 will move the contents of array element x[@y] to location z=zzz
(b) The operation -6 will move the contents of address x=xxx into array element y[@z]
example
+6 123 456 789 ;move the contents of data address 123+@456 to data location 789
Hence, if array A starts at address 123, and address 456 contain the index 15, then the contents of address 138=123+15 ( A[15]) is moved to address 789
-6 123 456 789 moves the contents of data address 123 to data location 456+@789
Hence, if array A starts at address 456, and address 789 contain the index 42, then the contents of address 123 is moved to address 498=456 + 42 ( contents of address 123 is moved to A[42])


loops (+7)
The value of the loop counter is stored in data address x=xxx, and the upper bound for theloop counter is stored in address y=yyy. The loop instruction takes the form +7 xxx yyy zzz, and signifies that the loop counter stored in data address x=xxx should be incremented, and if the loop counter (contents of the x=xxx) is then less than or equal to the upper bound (contents of z=yyy), then a jump should occur to program address z=zzz
example
+7 123 456 789 ;increment the contents of data address 123 (the loop counter). If this new value is less than or equal the value of data address 456 (the upper bopund for the loop) then program control is transferred to program location 789.


labels (-7)
Labels are inserted using the code -7, and are used as to signify locations in the program code to which JUMPS can occur. If labels are used, all instructions are of the form -7 0LL 000 000 where 0LL is a two-digit label, stored in a 100 element array
NOTE: yyy and zzz must be set at 000.
example
-7 012 000 000 ;label the program line as '12'
If labels are used, then all instruction which involve a jump (comparisons +4, -4, +5, -5, and loop +7) should use labels rather than absolute addresss for jumps.


read/print (+8, -8)
Reading and writing (printing) are accomplished via "cards". The original IBM 650 had no interactive input device, and all input was from a card reader. Similarly, output was to a card punch.
(a) The operation +8 will read the next card and place its value in location z=zzz
NOTE: xxx, yyy must be set at 000
(b) The operation -8 will print (to a card ?) the contents of address x=xxx
NOTE: yyy, zzz must be set at 000
example
+8 000 000 123 ;read the data on a card and place it in data location 123
-8 123 000 000 ;print the contents of data location 123

NOTES
You should assume that the program instruction locations start at address 0, and continue upward. In other words, the lines of instruction code (after the initialization section) are loaded into instruction addresses 0...999



INITIALIZATION OF VALUES (VARIABLES)
Initialization declarations appear in the initialization section, and are part of a "pair". Each value is defined by two lines of code, with the first the declaration of the location and "size" of the initialized memory location (variable) and the second the value to which the variable is being initialized. The use of the +0 code in the initialization section is to be interpreted as as a declaration. The value (variable) declaration is of the form +0 000 yyy zzz, where zzz = destination data address in which to store the value (variable) and yyy= length of variable. The next line in the pair of lines is of the form
±d ddd ddd ddd = initial value to which all "locations" of zzz are set.
example (must occur in initialization section, and must occur as a pair)
+0 000 002 042 ;declares a "variable" of length 2, stored in data location 42
+0 000 000 006 ;all entries initialized to 6
Hence, the values in data locations 42 and 43 are both intialized to the value 6.


IBM 650 Program Structure
The simplest solution to the requirements of loading the program into memory, initializing locations in data memory, and inputting data is to arrange the structure of as program so that it contain three parts, each separated by +99999999999. The interpreter can read initialization cards and store their contents into consecutive memory locations. Hence the structure of a program is of the form
program code comment
initial data values  +0 000 001 101 
+0 000 000 050 
+0 000 001 102 
+0 000 000 065 
+0 000 001 103 
+0 000 000 070 
+0 000 001 100 
+0 000 000 000 
VAR integer P, stored in loc 101 
P := 50 
VAR integer A, stored in loc 102 
A := 65 
VAR integer F, stored in loc 103 
F := 70
VAR integer X, stored in loc 100 
x := 0 
+9999999999 +9 999 999 999 end of initial data value "pairs"
prog instr +8 000 000 100
+5 100 101 010 
+8 103 000 000 
-4 100 100 099 
-7 010 000 000 
-8 102 000 000 
-7 099 000 000
read card, store value in X = loc 100 
comp X with P;if X >= P, jumpto label 10 print F (which contains 70) 
jumpto label 99 
label this program line as "10" 
print A (loc 102 which contains 65) 
label this program line as "99"
+9999999999 +9 999 999 999 STOP - end of instructions
input data (cards)  +0 000 000 072  input data cards go here

Please note that the above program initializes variables (locations) to the values P :=50 (the pass value), A:= 65 (the ASCII value for the character 'A') and F := 70 (the ASCII value for 'F').  It then reads a single value on a card (if more than one were to be processed a loop would be needed). It stores the value read in variable X, then compares the value of X to that of P. If X>= P, then transfer is passed to line labeled "10', and then the value of 'A' is printed. If the value of X is not large enough, then the value of 'F' is printed, after which transfer passes to line labeled '99'. Hence, in either case, a single value is printed, and then the program STOPS.


SYMBOLIC PSEUDOCODE ASSEMBLER

To ease the work of the IBM 650 programmer, and to make IBM 650 pseudocode programs easier to read, we will add the capability to write IBM 650 pseudocode programs using a mechanism which will associate with each part of the program instruction a SYMBOLIC string of characters. We shall use a three character alphanumeric name for each numeric address (xxx, yyy, zzz), and a four character operator name. This will allow the programmer to pick mnemonic variable names, and will leave to the loader/interpreter the task of dealing with the process of converting these character-based names into memory addresses.
 
 
Operation space operand 1 space operand2 space destination
columns 1-4  col5 columns 6-8 col 7 columns 10-12 col 13 columns 14-16

col width entry
1-4 4 operation
6-8 3 operand 1
10-12 3 operand 2
14-16 3 destination
 
 
Code
+
-
comments
0
MOVE
?
x => z ?
1 ADD SUB (x + y) => z (x - y) => z
2 MULT DIV ( x*y) => z  (x ÷ y) => z
3 SQR SQRT (x *x) => z sqrt(x) => z
4 EQ  NEQ if x = y, jumpto z if x <> y, jumpto z
5 GTEQ LT if x >= y jumpto z if x <y, jumpto z
6 GETA PUTA x[y] => z x => y[z]
7 LOOP LABL incr(x), loop to z if incr(x) <= y -7 0LL 000 000
8 READ PRNT read a card print a card
9 STOP (unused)

We will use the symbolic name VAR for the +0 operation as presented in the initialization section. The syntax will be of the form

VAR X 1
+42
which indicates that the variable named 'X' is to be a variable of length 1, and is to be initialized to value +42.

Hence the program given above could be written in pseudocode assembler as
machine code location assembler  comments
+0 000 001 100 000 VAR X 1 X, integer (stored in loc 100)
+0 000 000 000 001 +0 X := 0
+0 000 001 101 002 VAR P 1 P, integer (stored in loc 101)
+0 000 000 050 003 +50 P := 50
+0 000 001 102 004 VAR A 1 A, integer (stored in loc 102)
+0 000 000 065 005 +65 A := 65
+0 000 001 103 006 VAR F 1  F, integer (stored in loc 103)
+0 000 000 075 007 +70 F := 70
+9 999 999 999 008 STOP end of initialization section
+8 000 000 001 009 READ X read card, store value in X
+5 100 101 010 010 GTEQ X P PAS if X >= P, jumpto label PAS
+8 103 000 000 011 PRNT F print the value of variable F
+4 000 000 099 012 EQ X X END jump to program label END
+7 010 000 000 013 LABL PAS label this line PAS
-8 102 000 000 014 PRNT A print the value of variable A
+7 099 000 000 015 LABL END label this line END
+9 999 999 999 016 STOP stop execution- end of the program

 

LABEL TABLE and VARIABLE TABLE.

Using symbolic names for labels and variables also requires a LABEL TABLE and a VARIABLE TABLE. The LABEL TABLE is necessary in order to lookup labels, whose primary purpose is to ensure that the programmer need not deal with absolute addresses, but rather can deal with named addresses (labels). The label table should be built as the program is loaded into memory, so that we know that all labels are defined before program execution. Additionally, this allows us to increase security by ensuring that all labels that are referenced are defined once and only once.

One common technique is to initialize the the label table (address) entries to some value (such as -1) which can be interpreted as "undefined" . During program loading, whenever we encounter a -7 (LABL) instruction which defines a label, before we enter its absolute address into the label table, we ensure that it has not already been defined by seeing if its entry is negative. Similarly, when we encounter an instruction which refers to a label, we can check to see if it has not yet been defined (as indicated by a negative value), and if not, we can store the value -2 to indicate that the label has been referenced but not yet defined. If the label is later defined, then this -2 will be changed to a (positive) legitimate address value, reflecting the absolute location of the label. At the end of program loading, a final scan of the label table will indicate undefined labels as well as unreferenced labels.

Since the label table eliminates the error prone use of absolute statement labels, we can use a similar technique to construct a symbol table (the variable table) to hold the absolute location of every variable.
 
 
 

VARIABLE TABLE.                                                                               LABEL TABLE
name
size
data location 
label prog location
X
1
100
PAS
004
P
1
101
END
006
A
1
102
F
1
103

COMMENTS
 The semicolon (;) will be used as a saparator between program code and comments, so that any text following the semicolon (on a single line) will be considered a comment;