Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Notes on Variants on a Simple Program Statement | CPSC 2105, Study notes of Computer Architecture and Organization

Material Type: Notes; Class: Computer Organization; Subject: Computer Science; University: Columbus State University; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 08/04/2009

koofers-user-xmy
koofers-user-xmy 🇺🇸

5

(1)

10 documents

1 / 19

Toggle sidebar

Related documents


Partial preview of the text

Download Notes on Variants on a Simple Program Statement | CPSC 2105 and more Study notes Computer Architecture and Organization in PDF only on Docsity! Variants on a Simple Program Statement Begin with a program statement in some high–level language. Z = X + Y In the MARIE assembly language, this would be written as follows. Load X Add Y Store Z The hexadecimal representation of the MARIE machine language might be as follows. 10A2 30BC 202D How do we get to this hexadecimal representation? There are a few items to discuss before we really answer this one. 1. What is an accumulator and what is an accumulator–based machine? 2. What is assembly language and what is the function of the assembler? What is an Accumulator? The textbook definition of an accumulator is completely accurate. That definition might be expanded a bit. In a classic accumulator–based architecture, the accumulator, denoted “AC” or “ACC”, is the one register that holds temporary results from the computation. It accumulates the results, as in the above example in which it is used to accumulate the sum. The single accumulator architecture is an artifact of the days in which all registers were very expensive to build and took some trouble to maintain. Architectures with fewer general purpose registers (such as those with only one) were more reliable. For a good model of an accumulator, think of the single line display on a pocket calculator. The older ones had only one line of digits. The newer “full screen” units still have a line designated to hold the latest results. Think of each of these displays as an output unit copying the contents of a single accumulator. Early architectures added another register, called “MQ” to allow for multiplication and division. The multiplication of two 16–bit numbers gives a 32–bit result. Later architectures (except INTEL with the AX, BX, etc.) moved to a number of general purpose registers, often denoted by number: R0, R1, etc. More on the Assembler/Loader The assembler must allocate memory locations for each “variable” used in the computation. In more complex architectures, this needs to account for the number of bytes allocated for the variable: 2 or 4 bits for an integer, 4 or 8 bits for a real, etc. Again, the simplicity of the MARIE architecture is helpful. Only integers are used as data items. Each is exactly 16–bits long; one word per integer. Let’s expand the program slightly, so that its assembly will make sense. We have: 000 Load X 001 Add Y 002 Store Z 003 Halt 004 X, Dec 4 005 Y, Dec 8 006 Z, Dec 0 END Note the label notation, as in “X,”. It is a symbol followed by a comma. Assembler, Pass 1 Now we consider a two pass assembler, which is the “standard variety”. Pass One: This identifies the three symbols X, Y, and Z. It does so by scanning the labels at the beginning of the lines and finds “X,”, “Y,”, and “Z,”. In a more sophisticated assembler, the declarations for these three labels would identify the type of the variable: integer, real number, fixed length string, etc. In the MARIE, each variable is a 16–bit integer. At the end of Pass 1, the assembler has noted the addresses to be assigned to each “variable” and enrolled the names in its symbol table, which is used as a part of Pass 2 to associate each label with its unique address. Here is the symbol table generated after Pass 1 for this program Label Address X 0x004 Y 0x005 Z 0x006 Assembler, Pass 2 The output of pass 1 of the assembler may be imagined as follows. Each item has been assigned a location and all of the symbols used (think “variables”) have been identified. 000 Load X 001 Add Y 002 Store Z 003 Halt 004 X, Dec 4 005 Y, Dec 8 006 Z, Dec 0 END Recall the MARIE Instruction Format, shown in Figure 4.10 of the textbook. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 OpCode Address (represented as 3 hexadecimal digits) Note that the opcode, being the code that represents the instruction, is a binary number. It is often represented in hexadecimal, but almost never in decimal. Octal notation is occasionally used for the opcodes, but we shall avoid the practice. The Complete Program (Without Addresses) Load X Add Y Store Z Halt X, Dec 4 Y, Dec 8 Z, Dec 0 END This is the program as it would be input. Comment: One key difference between most assembly languages and high–level languages that are compiled is that the latter do not require explicit declaration of memory locations, as was done above. A compiler just requires a type definition, from which it will automatically generate the storage assignments. The SkipCond Instruction This is a zero–argument instruction that depends on the contents of the accumulator. It is described on pages 197 and 198 of the second edition of the textbook. Here is a version of the explanation. If IR[11–10] = 00, then skip the next instruction if AC < 0. If IR[11–10] = 01, then skip the next instruction if AC = 0. If IR[11–10] = 10, then skip the next instruction if AC > 0. I am greatly tempted to add a condition for IR[11–10] = 11, but shall resist. The opcode is 0x8. Look at the machine language. The basic template for all three instructions is: IR Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 0 0 0 0 0 0 0 0 0 0 0 8 0 0 More on SkipCond If IR[11–10] = 00, then skip the next instruction if AC < 0. IR Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 0 Assembled as 0x8000. Write as Skipcond 000 If IR[11–10] = 01, then skip the next instruction if AC = 0. IR Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 8 4 0 0 Assembled as 0x8400. Write as Skipcond 400 If IR[11–10] = 10, then skip the next instruction if AC > 0. IR Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 8 8 0 0 Assembled as 0x8800. Write as Skipcond 800 Disassembling the Program (Page 1) To disassemble the hexadecimal code, we must identify and determine the effect of each machine language instruction. Let’s do this one instruction at a time. Look at table 4.7 on page 172 of the textbook to get the definitions. 000 A000 This is an instruction to clear the accumulator. Clear 001 2009 This instruction stores the accumulator into an address. For lack of anything better, I am calling this W009 Store W009 002 5000 Input Place the input data into the accumulator Input 003 200A This stores the contents of the accumulator Store W00A 004 400B This subtracts a value from the accumulator Subt W00B Disassembling the Program (Page 2) 005 8800 This is Skipcond 800. Skip the next instruction if the AC > 0. Skipcond 800 006 7000 Halt Halt 007 2009 Store the accumulator contents into this address Store W009 008 7000 Halt. As there are no branches around this, it is the Halt last instruction to be executed. The next three words must hold data for the program. 009 0000 Decimal 0 00A 0000 Decimal 0 00B 0030 Decimal 48 Disassembling the Program (Page 3) We now list the pseudo–assembly language form of the program. At this point, we do not have any good names for the variables. 000 Clear // Clear the accumulator 001 Store W009 // Store the zero in this location 002 Input // Read from the input device. Call this N. 003 Store W00A // Store the raw input in this location. 004 Subt W00B // Subtract decimal 48 from the input. 005 Skipcond 800 // Skip if (N – 48) > 0, or N > 48. 006 Halt // Halt with 0 in W109 if N  48. 007 Store W009 // Store (N – 48) in W109 008 Halt // Halt 009 W009, Dec 0 00A W00A, Dec 0 00B W00B, Dec 48 // The ASCII value for the character ‘0’. This reads in the ASCII value of a digit and stores its numeric value in W109.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved