Programming Arithmetic And Logic Operations in Computer Architecture YASH PAL, February 28, 2026February 28, 2026 Programming Arithmetic and Logic Operations in Computer Architecture – Some of the computers perform a given operation with one machine instruction, while others may require a large number of machine instructions to perform the same operation. Lets a consider the four basic arithmetic operations and understand how a computer executes these arithmetic operations. Some computers have machine instructions to add, subtract, multiply, and divide. Others, such as the basic computer, have only one arithmetic instruction, such as ADD. Operations not included in the set of machine instructions must be implemented by a program. Operations that are implemented in a computer with one machine instruction are said to be implemented by hardware. Operations implemented by a set of instructions that constitute a program are said to be implemented by software. Some computers provide an extensive set of hardware instructions designed to speed up common tasks. Others contain a smaller set of hardware instructions and depend more heavily on the software implementation of many operations. Hardware implementation is more costly because of the additional circuits needed to implement the operation. Software implementation results in long programs both in the number of instructions and in execution time. Multiplication Program We will develop a program to multiply two numbers. We assume a positive number and neglect the sign bit for simplicity. And we also assume that the two binary numbers have no more than eight significant bits, so their product cannot exceed the word capacity of 16-bits. It is possible to modify the program to take care of the signs or use 16-bit numbers. However, the product may be up to 31 bits in length and will occupy two words of memory. The multiplication process consists of checking the bits of the multiplier Y and adding the multiplicand X as many times as there are 1’s in Y, provided that the value of X is shifted left from one line to the next. Since the computer can add only two numbers at a time, we reserve a memory location, denoted by P, to store intermediate sums. The intermediate sums are called partial products since they hold a partial product until all numbers are added. As shown in the numerical example under P, the partial product starts with zero. The multiplicand X is added to the content of P for each bit of the multiplier Y that is 1. The value of X is shifted left after checking each bit of the multiplier. The final value in P forms the products. The numerical example has numbers with four significant bits. When multiplied, the product contains eight significant bits. The computer can use numbers with eight significant bits to produce a product of up to 16 bits. Flowchart for multiplication program X: holds the multiplicandY: holds the multiplierP: holds the product Example with four significant digits X = 0000 1111 Y = 0000 1011 __________ 0000 1111 0001 1110 0000 0000 0111 1000 __________ 1010 0101 P ____________ 0000 0000 0000 1111 0010 1101 0010 1101 1010 0101 The program in the table below lists the instructions for multiplying two unsigned numbers. The initialization is not listed but should be included when the program is loaded into the computer. The initialization consists of bringing the multiplicand and multiplier into locations X and Y, respectively; initializing the counter to -8; and initializing location P to zero. If these locations are not initialized, the program may run with incorrect data. The program itself is straightforward and follows the steps listed in the flowchart. The comments may help in following the step-by-step procedure. ORG 100LOP,CLELDA YCIRSTA YSZEBUN ONEBUN ZRO/Clear E/Load multiplier/Transfer multiplier bit to E/Store shifted multiplier/Check if bit is zero/Bit is none: go to ONE/Bit is zero: go to ZROONE,LDA XADD PSTA PCLE/Load multiplicand/Add to partial product/Store partial product/Clear EZRO,LDA XCILSTA XISZ CTRBUN LOPHLT/Load multiplicand/Shift left/Store shifted multiplicand/Increment counter/Counter not zero; repeat loop/Counter is zero; haltCTR,DEC-8/This location serves as a counterX,HEX 000F/This location serves as a counterY,HEX 00B/Multiplicand stored hereP,HEX 0/Multiplier stored hereEND/Product formed hereA program to multiply two positive numbers Double Precision Addition When two 16-bit unsigned numbers are multiplied, the result is a 32-bit product that must be stored in two memory words. A number stored in two memory words is said to have double precision. When a partial product is computed, a double-precision number must be added to the shifted multiplicand, which is also a double-precision number. For greater accuracy, the programmer may wish to employ double-precision numbers and perform arithmetic with operands that occupy two memory words. We now develop a program that adds two double-precision numbers. One of the double-precision numbers is placed in two consecutive memory locations. AL and AH, with AL holding the 16 low-order bits. The other numbers are placed in BL and BH. The program is listed in the table given below. The two low-order portions are added, and the carry is transferred into E. The AC is cleared, and the bit in E is circulated into the least significant position of the AC. The two high-order portions are then added to the carry, and the double-precision sum is stored in CL and CH. LAD AL/Load A LowADD BL/Add B low, Carry in ESTA CL/Store in C lowCLA/Clear ACCIL/Circulate to bring carry into AC(16)ADD AH/Add A high and carryADD BH/Add B highSTA CH/Store in C highHLTAL,——/Locations of operandAH,——BL,——BH,——CL,——CH,——Program to add two double-precision numbers Logical Operation The basic computer has three machine instructions that perform logic operations: AND, CMA, and CLA. The LDA instruction may be considered as a logic operation that transfers a logic operand into AC. We listed 16 different logic operations. All 16 logic operations can be implemented by software means because any logic function can be implemented using the AND and complement operations. For example, the OR operation is not available as a machine instruction in the basic computer. From DeMorgan’s theorem, we recognize the relation x+y=(x’y’)’. The second expression contains only AND and complement operations. A program that forms the OR operation of two logic operands, A and B, is as follows: LDAALoad first operand ACMAComplement to get ASTA TMPStore in a temporary locationLDABLoad second operand BCMAComplement to get BAND TMPAND with A to get A ∧ BCMAComplement again to get A v BOR operation of two logic operands Shift Operations The circular-shift operations are machine instructions in the basic computer. The other shifts of interest are the logical shifts and arithmetic shifts. These two shifts can be programmed with a small number of instructions. The logical shift requires that zeros be added to the extreme positions. This is easily accomplished by clearing E and circulating the AC and E. Thus, for a logical shift-right operation, we need the two instructions. CLE CIR For a logical shift-left operation, we need the two instructions. CLE CIL The arithmetic shifts depend on the type of representation of negative numbers. For the basic computer, we have adopted the signed-2’s complement representation. The rules for arithmetic shifts are listed in the Shift Micro Operations Article. For an arithmetic right-shift, it is necessary that the sign bit in the leftmost position remain unchanged. But the sign bit itself is shifted into the high-order bit position of the number. The program for the arithmetic right shift requires that we set E to the same value as the sign bit and circulate right, thus: CLE /Clear E to 0 SPA /Skip if AC is positive; E remains 0 CME /AC is negative; set E to 1 CIR /Circulated E and AC Computer System Architecture engineering subjects Computer System Architecture