Description of RAMM Instructions

00 yy

HLT

Halt

 

12 yy

LDA

Load A register

(A reg) = (yy)

14 yy

IAD

Integer Add

(A reg) = (A reg) + (yy)

15 yy

ISB

Integer Subtract

(A reg) = (A reg) - (yy)

16 yy

LDQ

Load Q register

(Q reg) = (yy)

20 yy

STA

Store A register

(yy) = (A reg)

21 yy

STQ

Store Q register

(yy) = (Q reg)

24 yy

IMU

Integer Multiply

(A reg) = least significant 4 digits of ( (A reg) * (yy) )
(Q reg) = most significant 4 digits of ( ( A reg) * (yy) )

25 yy

IDV

Integer Divide

(A reg) = int quotient of ( (A reg) / (yy)
(Q reg) = int remainder of ( (A reg) / (yy) )

36 yy

AZJ

Jump to location yy if (A reg) is zero

 

37 yy

AMJ

Jump to location yy if (A reg) is negative

 

50 yy

NOP

No Operation

 

65 yy

RDI

Read Decimal Integer

(yy) = value input from keyboard or input file

66 yy

PRI

Print Decimal Integer

Print (yy) as an integer on output line

75 yy

UNJ

Unconditional Jump to location yy

 

99 yy

END

End of program, begin execution at yy

 
  BSS k

Reserve k storage locations (k³0)

 
  DEC k

Create decimal constant of k (-999£k£ 9899)

 

 

 

00yy   HLT       Halt

This instruction causes execution of the program to terminate. The operand yy is ignored in execution.

Example: Suppose that we have the following instruction sequence and execution begins at memory location 15.

(15) =

1204

(16) =

1407

(17) =

2003

(18) =

0000

After loading the A-register with the contents of memory location 04 and adding to that the value of the contents of memory location 07 and storing the sum that is left in the A-register into memory location 03, program execution terminates. When a HLT instruction is encountered in program execution the computer prints a message similar to the one listed below:

Halt 0000 Encountered at Location (18)
4 Instructions Executed

 

 

12yy   LDA       Load A-register

This instruction replaces the contents of the A-register with a copy of the contents of memory location yy. The initial contents of the A-register are destroyed and the contents of yy are unchanged.

Initial values are:

(A-register) =

2356

(05) =

0123

Example: Suppose that the following instruction is given:

1205

Execution of this instruction causes the following registers and memory locations to be affected:

(A-register) =

0123

(05) =

0123




14yy   IAD       Integer Add

This instruction adds a copy of the contents of memory location yy to the contents of the A-register and leaves the sum in the A-register. The initial contents of the A-register are destroyed and the contents of memory location yy are unchanged. If overflow occurs, an error message will be output and execution of the program will continue. Note that prior to issuing the IAD instruction, one of the addends should already be in the A-register. This can be accomplished by a load instruction or possibly as the result of another arithmetic operation.

Initial values are:

(A-register) =

2356

(03) =

0005

(04) =

0012

Example: Suppose that the following instruction sequence is given:

1203
1404

After execution of this instruction sequence, the final contents of the A-register and memory locations involved would be as follows:

(A-register) =

0017

(03) =

0005

(04) =

0012

Note that the LDA instruction (1203) loaded the first addend into the A-register. After execution of the LDA instruction, the A-register contained 0005. The IAD instruction then caused the 0005 contained in the A-register to be added to the 0012 that was contained in memory location 04 and the sum of the two values, namely 0017, was placed in the A-register.It is possible for a situation called OVERFLOW to occur after execution of an addition or subtraction instruction. Overflow occurs when a sum or difference of two 4-digit numbers cannot be contained in the four-digit A-register. For example, if the numbers 9999 and 0001 were added together, the sum would be 10000. Obviously, you can't put a 5-digit number into a 4-digit register. The computer will issue a message in the output window on the screen that overflow has occurred at the memory location that contained the IAD instruction. The contents of the A-register would be 0000 (sum mod 104). Execution of the program will continue with the next instruction in the program. Note that the overflow condition can occur in execution of both IAD and ISB instructions.




15yy   ISB       Integer Subtract

This instruction subtracts a copy of the contents of memory location yy from the contents of the A-register and leaves the difference in the A-register. The initial contents of the A-register are destroyed and the contents of yy are unchanged. If overflow occurs, an error message will be output on the screen and in the output window and execution will continue. Normally one of the numbers to be used in the ISB instruction (the minuend) will be placed in the A-register prior to issuing the subtract instruction.

Initial contents are:

(A-register) =

0017

(04) =

0012

(05) =

0123

Example: Suppose that the following instruction sequence is given:

1205
1504

After execution of this instruction sequence, the register and memory locations affected would be as follows:

(A-register) =

0111

(04) =

0012

(05) =

0123

In the execution of this instruction sequence, the LDA instruction would have caused the A-register to contain a copy of the contents of memory location 05, namely 0123. The ISB instruction caused the contents of location 04, namely 0012, to be subtracted from the value in the A-register and the difference of the two values is placed in the A-register. In other words, this instruction sequence performed the subtraction of 0012 from 0123 and generated the difference, 0111. An overflow condition can be caused by subtracting two negative numbers that would generate a negative value of magnitude greater than -9999. For example, - 9999 - 1 = - 10000. The computer would give an overflow message in the output window and on the screen and execution would continue with the next instruction in the program. Also, the contents of the A-register would be 0000 (-10000 mod 104).




16yy   LDQ       Load Q-register

This instruction replaces the contents of the Q-register with a copy of the contents of memory location yy. The initial contents of the Q-register are destroyed and the contents of location yy are unchanged.

Initial contents are:

(Q-register) =

1789

(03) =

0005

Example: Suppose that the following instruction is given:

1603

After execution of this instruction, the contents of the affected register and memory location would be as follows:

(Q-register) =

0005

(03) =

0005




20yy   STA       Store A-register

This instruction replaces the contents of memory location yy with a copy of the contents of the A-register. The initial contents of yy are destroyed and the contents of the A-register are unchanged.

Initial contents are:

(A-register) =

2356

(07) =

0003

Example: Suppose that the following instruction is given:

2007

After execution of the STA instruction, the contents of the affected register and memory location would be as follows:

(A-register) =

2356

(07) =

2356

The STA instruction merely takes a copy of the contents of the A-register and places it in the memory location whose address is 07.




21yy   STQ       Store Q-register

This instruction replaces the contents of memory location yy with a copy of the contents of the Q-register. The initial contents of yy are destroyed and the contents of the Q-register are unchanged.

Initial contents are:

(Q-register) =

1789

(05) =

0123

Example: Suppose that the following instruction is given:

2105

After execution of this instruction the final contents of the register and memory location affected would be as follows:

(Q-register) =

1789

(05) =

1789




24yy   IMU       Integer Multiply

This instruction multiplies two 4-digit integers, forming an eight-digit product. The multiplicand must be in the A-register before execution of the IMU instruction. The multiplier is a copy of the contents at memory location yy. The product is contained in the combined QA-registers as an 8-digit integer. The least significant 4 digits of the product (low order digits) are contained in the A-register and the most significant 4 digits are contained in the Q-register. The initial contents of both the A- and Q-registers are destroyed. The contents of yy are unchanged.

Initial contents are:

(A-register) =

2356

(Q-register) =

1789

(04) =

0012

(05) =

0123

Example: Suppose that the following instruction sequence is given:

1204
2405

After execution of the instruction sequence, the memory location and registers affected would be as follows:

(Q-register) =

0000

(A-register) =

1476

(04) =

0012

(05) =

0123

Note that in this example all of the significant digits of the product can be contained in the A-register and thus the Q-register contains all zeroes. In practice, we normally know the range of products the values will have and if the significant digits of the product are four digits or less we only save the contents of the A-register after a multiply operation. Overflow cannot occur in a multiplication operation in RAMM since the largest product that could be generated by two 4-digit numbers would be 9999 x 9999 = 99980001 and this product is represented by only 8 digits. If the IMU instruction were given both multiplier and multiplicand of 9999 the product would be placed in the registers as follows:

(Q-register) =

9998

(A-register) =

0001




25yy   IDV       Integer Divide

This instruction divides a 4-digit integer by a 4-digit integer producing a 4-digit integer quotient and a 4-digit integer remainder. The 4-digit integer to be divided (the dividend) must be loaded into the A-register before the execution of the divide instruction. The divisor is a copy of the contents of memory location yy. After execution of the IDV instruction the A-register contains the integer quotient and the Q-register contains the integer remainder.

Initial contents are:

(A-register) =

2356

(Q-register) =

1789

(03) =

0005

(05) =

0123

Example: Suppose that the following instruction sequence is given:

1205
2503

After execution of the instruction sequence the memory location and registers involved would be as follows:

(A-register) =

0024

(Q-register) =

0003

(03) =

0005

(05) =

0123

Note that the quotient in the A-register is the integer quotient. We normally save only the A-register after a divide operation. We call this quotient a truncated quotient since the fractional portion of the quotient is truncated or left off the answer. We could generate a rounded quotient if we were to examine the contents of the Q-register and if these contents were greater than or equal to one-half the divisor we add 1 to the integer quotient in the A-register. In both cases an error is introduced that may gradually get worse if we continue to use this quotient in subsequent arithmetic operations. The error that is introduced as a result of saving truncated quotients is a fraction expressed as (divisor - 1) / divisor. For example if the divisor were 5000 then the error that could be introduced could be as large as 4999 / 5000 or almost 1. Each time we use this truncated quotient in another IDV operation we get another truncated quotient that has an error of almost 1. If we performed divide operations on ten successive quotients and used the truncated quotient each time in the next division, the final result could have an error as large as 10.

Overflows are impossible with the integer divide operation. A 4-digit dividend and a 4-digit divisor can generate a quotient with a maximum of 4 digits and a remainder with a maximum of 4 digits.




36yy   AZJ       Jump if A-register is Zero

If the A-register contains zero, the current sequence of control is terminated and a new sequence is begun at location yy. The next instruction to be executed is contained in memory location yy. If the A-register contains a non-zero number, the current sequence of control continues. The contents of all memory locations and the A- and Q-registers are unchanged by this instruction. This is one of the two instructions in RAMM called conditional transfer instructions. A branch is made on the condition that the A-register contains zero at that point in the program. The mnemonic AZJ could represent "A-Register is Zero, Jump."

Example: Suppose that the contents of the A-register are zero and the following instruction sequence with memory addresses as listed appears in a program:

 

.

(45) =

3650

(46) =

1204

 

.

 

.

 

.

(50) =

1207

(51) =

1503

 

.

 

.

If we pick up program execution at memory location 45 in this example, since the contents of the A-register are zero, a transfer of control is made to memory location 50 for the next instruction. A new sequence of control is begun at location 50. If the contents of the A-register had not been zero when the AZJ instruction was encountered then the next instruction executed after location 45 would have been the instruction at location 46.




37yy   AMJ       Jump if A-register is negative (minus)

If the A-register contains a negative number, the current sequence of control is terminated and a new sequence is begun at location yy. The next instruction to be executed is the contents of memory location yy. If the A-register contains a positive number or zero, the current sequence of control continues. The contents of all memory locations and the A- and Q-registers are unchanged by this instruction. The mnemonic AMJ stands for "A-Register Minus, Jump." The AMJ instruction is one of two conditional branch instructions in RAMM.

Using the AZJ and AMJ instructions together allows you to implement three branches of a decision symbol in a flowchart. Compare value A to value B by computing A - B, leaving the result in the A-Register.

A - B = 0

implies

A = B

A - B = negative value

implies

A < B

A - B = positive value

implies

A > B

A combination of AZJ and AMJ can check the case of a positive result since if the result is not zero or negative, then it must be positive.

Example: Suppose that the following instruction sequence is given with memory locations as indicated and suppose that the A-register currently contains a negative number.

 

. . .

(60) =

3772

(61) =

1204

 

. . .

(72) =

1205

(73) =

1403

 

. . .

If we pick up the program execution at memory location 60, then the next instruction to be executed is at memory location 72. A new sequence of control is begun at 72. If the A-register had not contained a negative value at this point in the program then the next instruction executed after the AMJ instruction would have been at memory location 61.

Example: Compare two values and make a branch based upon this comparison. Suppose that we have the following memory contents and instructions listed below:

 

.

(10) =

0004

(11) =

0007

 

. . .

(20) =

1211

(21) =

1510

(22) =

3730

(23) =

3640

(24) =

1205

 

. . .

Suppose that we pick up program execution at location 20. Here we are comparing the contents of location 10 to the contents of location 11. The result in the A-register after execution of the ISB instruction at location 21 would be 0003. Since this is not a negative value the branch specified by the AMJ instruction at location 22 would not be taken and since the A-register is not zero the branch specified by the AZJ instruction at location 23 is also not taken. Thus the next instruction executed after this sequence of steps is the instruction at memory location 24. This is an example of using AMJ and AZJ instructions together to get the net effect of "A-Register Positive, Jump" function. We don't need an APJ because we use AMJ and AZJ together to achieve the same result.

 

50yy   NOP       Pass - No Operation

This instruction causes no operation to be performed. The current sequence of control continues. The operand yy is ignored during the execution of the instruction. The purpose of the NOP is to allow the programmer to place one or more "do nothing" instructions in a sequence of program code. In subsequent revisions of the program, the programmer may wish to replace these NOP instructions with other code. The "do nothing" instructions may also be used as "place holders" for instructions to be computed or modified during execution. The ability of the programmer to cause the program to dynamically change itself during execution is one of the most powerful techniques available in machine language programming.Example: Suppose the following code segment is given at the memory locations indicated and that execution begins at memory location 33.

 

. . .

(33) =

1204

(34) =

1405

(35) =

2007

(36) =

5000

(37) =

1205

 

. . .

This code caused the contents of memory location 04 to be added to the contents of memory location 05 and the sum stored in memory location 07. Execution of the NOP instruction at location 36 causes no change in the registers or memory locations and the sequence of control would pass on to memory location 37.




65yy   RDI       Read Decimal Integer

This instruction reads a decimal integer from the input stream (either a data file or value input through the keyboard) and stores the value in the memory location whose address is yy. The initial contents of yy are destroyed and the contents of the A- and Q-registers are unchanged. The RDI instruction allows us to input values in an executing program. The value read in replaces the value currently stored in memory location yy.

Example: Suppose that the following memory contents are given at the memory locations indicated:

 

.

(10) =

0019

 

.

 

.

 

.

(35) =

6510

 

.

 

.

If we pick up program execution at location 35, the RDI instruction will request that you input a value by displaying a dialog box on the screen with the message: "Input a value." You should input a data value in the range -999 to 9999. If you input the value 0345 through the keyboard, then after execution of the RDI instruction, the contents of memory location 10 would be 0345.




66yy   PRI       Print Decimal Integer

This instruction prints on the next output line the integer stored in memory location yy. The contents of yy and the A- and Q-registers are unchanged. The PRI instruction produces output by listing the address of the memory location to be printed out and then the contents of that memory location, for example "(96) = 0012" would be generated by the instruction 6696 if memory location 96 contained the value 0012. The PRI instruction is the only means to output values from a RAMM program. Note that the only values that can be printed are 4-digit decimal integers.

Example: Suppose that the following code sequence is given with memory contents as indicated:

 

.

(23) =

1234

 

.

 

.

 

.

(27) =

9988

 

.

 

.

(35) =

6623

(36) =

6627

If we pick up program execution at memory location 35, the PRI instructions would cause the following output to be listed on the screen:

(23) = 1234
(27) = 9988




75yy   UNJ       Unconditional Jump

This instruction terminates the current sequence of control and starts a new sequence at memory location yy. The next instruction to be executed is the contents of yy. The contents of all memory locations and the A- and Q-registers are unchanged by this instruction. We also call this instruction an unconditional branch instruction. The current sequence of control in a program is that order of execution in which, when the current instruction has finished executing, the next instruction to be executed is stored in the next consecutive memory location. The UNJ instruction is one of three instructions that can cause a transfer of control in a program.

Example: Suppose we are given the following instruction sequences located at the memory locations indicated:

 

.

(23) =

7532

(24) =

1204

 

. . .

(32) =

1205

(33) =

1403

 

. . .

If we pick up program execution at memory location 23 and execute the instruction contained there, then the next instruction executed after the unconditional jump instruction at location 23 will be at memory location 32 and program control will continue to location 33 and subsequent consecutive memory locations until a new transfer of control instruction is given.




99yy   END       End program loading

This instruction indicates the end of the program loading operation and also specifies that execution of the program is to begin at memory location yy. The END instruction is the last instruction of any RAMM program. Since END is processed during the program-loading phase, that is, the phase where the program is stored into the RAMM computer memory, it cannot be considered an executable instruction. The HLT instruction is used to terminate execution of the program while the END instruction is used to terminate loading of the program. If the END instruction is encountered during execution of a program, the 99 operation code causes termination of processing with an error message that an illegal operation code was encountered.

Example: Suppose that the following code sequence is given:

(65) =

1204

(66) =

1403

(67) =

2005

(68) =

6605

(69) =

0000

(70) =

9902

As the RAMM program is loaded into memory of the RAMM computer the instruction that is loaded into memory location 70 causes the loading operation to be terminated. Notice that the HLT instruction in location 69 was not recognized as a halt at the time that the program was loaded into the RAMM computer memory since the only instruction that is actually processed during the program loading phase is the 99 (END) instruction. After the END instruction is processed the program will begin execution at memory location 02 when the programmer specifies that he wishes to "run" or execute the program.

END in Assembly Language

The END pseudo-instruction signifies the end of a program and must be the last statement in the program. The instruction terminates the assembly (translation) process and also the loading process. If no fatal assembly errors have occurred execution will begin at memory location yy when the programmer specifies that he wishes to "run" or execute the program. If yy is omitted, execution begins at location 00. A symbol in the location field is illegal.




BSS k       Reserve k storage locations

The BSS pseudo-instruction reserves k consecutive memory locations starting at the current location. The contents of the locations reserved are not altered by this instruction. The constant k must be an unsigned RAMM constant. If k=0, the symbol occurring in the location field is assigned to the current location but no memory location is reserved.




DEC k       Create constant

The DEC pseudo-instruction stores the (decimal) RAMM constant k in the current location. If a symbol occurs in the location field, it is assigned to the current location.