Prior Page     Next Page     This Chapter    Prior Chapter    Next Chapter







Hermes Computer Arithmetic Operations

The arithmetic on the Hermes computer provides 32-bit binary twos-complement machine arithmetic. Overflow in addition, subtraction, and division is detected and is recorded in the condition code. There is little to surprise here.

For example, The instruction ADD 0,0x001010 will add signed 32-bit number found starting in memory location 0x001010 (4-bytes) to the value in register 0, with the result replacing the value in register 0. The instruction SUB 15,0x00101e will subtract a signed 32-bit number found starting in memory location 0x001010 (4-bytes) to the value in register 15, with the result replacing the value in register 15.

Note there is no method of adding or subtracting a halfword in memory to or from a register. One must load the halfword into a register (using LH) first and then do 32-bit arithmetic on it.

Multiplication holds some surprises. On the Hermes machine, multiplication will never overflow, but it does produce a double-sized product that occupies two registers. If you remember your p's and q's from the notes on bits and bytes, multiplication of two p-bit numbers produces a 2p-bit number. The Hermes multiply operation puts the high-order half (sign and 31-bits) in the smaller numbered register and the 32-bits of the low-order half in the next higher numbered register.

If the high-order register is all zeros, or all ones, then the high-order bit of the second register can be treated as a sign bit. It the high-order register has mixed zeros and ones then the high-order bit of the second register can not be relied on as a sign bit, basically the resulting product is greater than 2³² and thus the multiplication `overflowed' into the high-order register. The overflow flag is not set in the condition-codes because the machine produces a full 64-bit product. You can check the high-order register for overflow, by doing a logical operation on the register, then test and branch on mixed bits.

An example of multiplication, assume 5 is in register 3, and the value 10 is in memory location 0x002000. Then the instruction MUL  3,0x002000 will produce 0 in reg 3, and 50 in reg 4. It is unexpected but true that generally you get the result of multiplication from the register after the one you used in the multiply instruction. That is we multiplied by register 3, and we get the result in register 4.

Similarly, division takes the number in the second half of a double register (say 3 and 4 which means the dividend goes into 4) and the divisor is in memory. It will produce the quotient of the division in reg 3, and remainder in reg 4. Put 50 in reg 4 and then divide by a 7 in memory location 0x002000; that produces a 7 in reg 3 and a 1 in reg 4.








Prior Page     Next Page     This Chapter    Prior Chapter    Next Chapter


Copyright © 1995 R. Uzgalis. All rights reserved.
Contact: buz@cs.aukuni.ac.nz