Assembler CASE Tool Instructions COMPUTERBC INSTRUCTIONS Basic Computer
Assembler CASE Tool
Instructions COMPUTER(BC) INSTRUCTIONS Basic Computer Instruction code format Memory-Reference Instructions 15 I 14 12 11 Opcode Address Register-Reference Instructions 15 0 1 0 (OP-code = 111, I = 0) 12 11 0 1 1 Register operation Input-Output Instructions 15 1 1 (OP-code = 000 ~ 110) (OP-code =111, I = 1) 12 11 0 I/O operation 1 1
Instructions BASIC COMPUTER INSTRUCTIONS Hex Code I=0 I=1 0 xxx 8 xxx 1 xxx 9 xxx 2 xxx Axxx 3 xxx Bxxx 4 xxx Cxxx 5 xxx Dxxx 6 xxx Exxx Description AND memory word to AC Add memory word to AC Load AC from memory Store content of AC into memory Branch unconditionally Branch and save return address Increment and skip if zero CLA CLE CMA CME CIR CIL INC SPA SNA SZE HLT 7800 7400 7200 7100 7080 7040 7020 7010 7008 7004 7002 7001 Clear AC Clear E Complement AC Complement E Circulate right AC and E Circulate left AC and E Increment AC Skip next instr. if AC is positive Skip next instr. if AC is negative Skip next instr. if AC is zero Skip next instr. if E is zero Halt computer INP OUT F 800 F 400 Input character to AC Output character from AC Symbol AND ADD LDA STA BUN BSA ISZ
Machine Language MACHINE LANGUAGE Program A list of instructions or statements for directing the computer to perform a required data processing task Various types of programming languages - Hierarchy of programming languages • Machine-language - Binary code - Octal or hexadecimal code • Assembly-language - Symbolic code (Assembler) • High-level language (Compiler)
Machine Language COMPARISON OF PROGRAMMING LANGUAGES • Binary Program to Add Two Numbers Location 0 1 10 11 100 101 110 LDA ADD STA HLT 0053 FFE 9 0000 Instruction Comments 004 Load 1 st operand into AC 005 Add 2 nd operand to AC 006 Store sum in location 006 Halt computer 1 st operand 2 nd operand (negative) Store sum here • Fortran Program INTEGER A, B, C DATA A, 83 / B, -23 C=A+B END Location 000 001 002 003 004 005 006 Instruction Code 0010 0000 0100 0001 0000 0101 0011 0000 0110 0111 0000 0001 0000 0101 0011 1111 1110 1001 0000 • Program with Symbolic OP-Code Location 000 001 002 003 004 005 006 • Hexa program Instruction 2004 1005 3006 7001 0053 FFE 9 0000 • Assembly-Language Program A, B, C, ORG LDA ADD STA HLT DEC DEC END 0 A B C 83 -23 0 /Origin of program is location 0 /Load operand from location A /Add operand from location B /Store sum in location C /Halt computer /Decimal operand /Sum stored in location C /End of symbolic program
Assembly Language ASSEMBLY LANGUAGE Syntax of the BC assembly language Each line is arranged in three columns called fields Label field - May be empty or may specify a symbolic address consists of up to 3 characters - Terminated by a comma Instruction field - Specifies a machine or a pseudo instruction - May specify one of * Memory reference instr. (MRI) MRI consists of two or three symbols separated by spaces. ADD OPR (direct address MRI) ADD PTR I (indirect address MRI) * Register reference or input-output instr. Non-MRI does not have an address part * Pseudo instr. with or without an operand Symbolic address used in the instruction field must be defined somewhere as a label Comment field - May be empty or may include a comment
Assembly Language PSEUDO-INSTRUCTIONS ORG N Hexadecimal number N is the memory loc. for the instruction or operand listed in the following line END Denotes the end of symbolic program DEC N Signed decimal number N to be converted to the binary HEX N Hexadecimal number N to be converted to the binary Example: Assembly language program to subtract two numbers MIN, SUB, DIF, ORG 100 LDA SUB CMA INC ADD MIN STA DIF HLT DEC 83 DEC -23 HEX 0 END / Origin of program is location 100 / Load subtrahend to AC / Complement AC / Increment AC / Add minuend to AC / Store difference / Halt computer / Minuend / Subtrahend / Difference stored here / End of symbolic program
Assembly Language TRANSLATION TO BINARY Hexadecimal Code Location Content 100 101 102 103 104 105 106 107 108 2107 7200 7020 1106 3108 7001 0053 FFE 9 0000 Symbolic Program MIN, SUB, DIF, ORG 100 LDA SUB CMA INC ADD MIN STA DIF HLT DEC 83 DEC -23 HEX 0 END
Assembler ASSEMBLER - FIRST PASS - Assembler Source Program - Symbolic Assembly Language Program Object Program - Binary Machine Language Program Two pass assembler 1 st pass: generates a table that correlates all user defined (address) symbols with their binary equivalent value 2 nd pass: binary translation First pass LC : = 0 Scan next line of code Set LC yes Label no ORG no yes Store symbol in addresssymbol table together with value of LC Increment LC END no yes Go to second pass
Assembler ASSEMBLER - SECOND PASS - Second Pass Machine instructions are translated by means of table-lookup procedures; (1. Pseudo-Instruction Table, 2. MRI Table, 3. Non-MRI Table 4. Address Symbol Table) Second pass LC <- 0 Done Scan next line of code Pseudo instr. Set LC yes no ORG yes END no no yes MRI Get operation code and set bits 2 -4 Search addresssymbol table for binary equivalent of symbol address and set bits 5 -16 yes Set first bit to 1 I no no Valid non-MRI instr. DEC or HEX Convert operand to binary no and store in location given by LC yes Store binary equivalent of instruction in location given by LC Error in line of code Set first bit to 0 Assemble all parts of binary instruction and store in location given by LC Increment LC
Assignment • Construct Basic computer Assembler using C# windows application as following:
- Slides: 11