330 likes | 578 Views
Chapter # 6. PROGRAMING THE BASIC COMPUTER. Machine language Assembly language The Assembler Program Loops Programming Arithmetic and Logic Operations Subroutines Input-Output Programming. Contents. Table 6-1 Computer Instruction. Sym. I=0 I=1. Description. AND. 0xxx. 8xxx.
E N D
Chapter # 6 PROGRAMING THE BASIC COMPUTER
Machine language Assembly language The Assembler Program Loops Programming Arithmetic and Logic Operations Subroutines Input-Output Programming Contents
Table 6-1Computer Instruction Sym I=0 I=1 Description AND 0xxx 8xxx And Memory to AC 1xxx 9xxx ADD Add Memory to AC LDA 2xxx Axxx Load To AC STA 3xxx Store Of AC Bxxx BUN Branch Uncondionary 4xxx Cxxx BSA 5xxx Dxxx Return Address ISZ 6xxx Exxx Skip If Zero
Clear AC Clear E Comp. AC Comp. E Cir. Right AC and E Cir. Left AC and E Increment AC Skip If AC is Positive Skip If AC is Negative Skip If AC is Zero Skip If E is 0 Halt Computer Table 6-1 Instruction CLA 7800 CLE 7400 CMA 7200 7100 CME CIR 7080 CIL 7040 INC 7020 7010 SPA 7008 SNA 7004 SZA SZE 7002 7001 HLT
Instruction For Computer INP F800 Input to AC OUT F400 Output From Ac F200 SKI Skip on Input Flag F100 SKO Skip On Output Flag ION F080 Interrupt On IOF F040 Interrupt Off
Table 6-4Symbolic Operation Code Location Instruction Comments 000 LDA 004 Load First operand In AC 001 ADD 005 Add second operand to Ac 002 STA 006 Store in location 006 003 HLT Halt Computer 004 0053 First Operand 005 FFE9 Second Operand is Negative 006 0000 Store Sum Here
Table 6-3Hexadecimal Add two Number Location Instruction 000 2004 001 1005 002 3006 003 7001 004 0053 005 FFE9 006 0000
Table 6-2Binary to Add Two Numbers Location Instruction Code 0 0010 0000 0000 0100 1 0001 0000 0000 0101 10 0011 0000 0000 0110 11 0111 0000 0000 0001 100 0000 0000 0101 0011 101 1111 1111 1110 1001 110 0000 0000 0000 0000
Table 6-5Assembly Language Program ORG 0 Origin is 0 LDA A Load operation A ADD B Add operation B STA C Store Location C HLT Halt Computer A, DEC 83 Decimal Operand B, DEC –23 Decimal Operand C, DEC 0 Store in Location C END End Of Program
Table 6-6Fortran Program to ADD Two Number Integer A, B, C Data A, 83 B, -23 C = A+B End
Table 6-7Definition Of Pseudoinstructions Symbol Information For Assembler ORG N N operation for hexadecimal operand listed line. END End of Program DEC N N converted to Binary HEX N Hexadecimal Converted to Binary
Instruction Field of Program CLA NON-MRI ADD OPR DIRECT ADDRESS MRI ADD PTR I INDIRECT ADDRESS MRI
Table 6-8Assembly language program subtract Two number ORG 100 ORIGIN LOCATION IS 100 LDA SUB LOAD TO AC CMA COMPLEMENT AC INC INCREMENT AC ADD MIN ADD TO AC STA DIF STORE DIFFERENCE HLT HALT COMPUTER MIN, DEC 83 MINUEND SUB, DEC –23 SUMTRAHEND DIF, HEX 0 DIFFERENCE STORE HERE END END PROGRAM
Table 6-9translated program of table 6-8 HEXADECIMAL LOCATION CINTENT SYMBOLIC PROGRAM ORG 100 100 2107 LDA SUB 101 7200 CMA 102 7020 INC 103 1106 ADD MIN 104 3108 STA DIF 105 7100 HLT 106 0053 MIN, DEC 83 107 FFE9 SUB, DEC -23 108 0000 DIF, HEX0 END
Address symbol Table ADDRESS SYMBOL HEXADECIMAL MIN 106 SUB 107 DIF 108
Table 6-11line of code: pl3, ld,sub1 Memory word symbol hex-code binary represent 1 PL 50 AC 0101 0000 0100 1100 2 3, 33 2C 0011 0011 0010 1100 3 L D 4C 44 0100 1100 0100 0100 4 A 41 20 0100 0001 0010 0000 5 SU 53 55 0101 0011 0101 0101 6 B 42 20 0100 0010 0010 0000 7 I CR 49 OD 0100 1001 0000 1100
Figure 6-1First pass of assembler First pass LC 0 Scan line code Set LC Yes ORG Label No No Yes Yes End Store symbol in Address symbol With Ac Go to second pass No Increment LC
Table 6-12Address symbol MEMORY SYMBOL HEX-CODEBinary rep.. WORD ( LC ) 1 M I 4D 49 0100 1101 0100 1001 2 N , 4E 2C 0100 1110 0010 1100 3 (LC) 01 06 0000 0001 0000 0110 4 S U 53 55 0101 0011 0101 0101 5 B , 42 2C 0100 0010 0010 1100 6 (LC) 01 07 0001 0001 0000 0111 7 DI 44 49 0100 0100 0100 1001 8 F 46 2C 0100 0110 0010 1100 9 (LC) 01 08 0000 0001 0000 1000
Figure 6-2Flowchart for second pass of assembler LC 0 DONE Scan next line of code Set LC yes yes ORG END no Pseudo instruction yes no DEC or HEX no yes no MRI Convert operand To binary and store In location Given by LC Valid Non-MRI instruction Get operation code and set bits 2-4 no Search address symbol Table for binary equivalent Of symbolic address And set bits 5-16 yes Store binary Equivalent of Instruction In loaction given By LC Error in line Of code yes no I Set first bit to 1 Set first Bit to 0 Assemble all parts and store In location give by LC Increment LC
Table 6-13Program to Add 100 Number Line 1 2 3 4 5 6 7 Lop, 8 9 10 13 ADS, 14 PTR, 15 NBR, 16 CTR, 17 SUM, 118 119 Org 100 LDA ADS STA PTR LDA NBR STA CTR CLA ADD PTR1 ISZ PTR ISZ CTR BUN LOP HEX 150 HEX 0 DEC –100 HEX 0 HEX 0 DEC 23 END / Origin is HEX 100 / Load First Address Of Operand / Store in Pointer / Load Minus 100 / Store in Counter / Clear Ac / Add To Ac / Inc Pointer / Inc Counter / Loop Again / First Address Of Operand / Reserved for Pointer / Initialized Counter / Reserved For Counter / Sum is Stored Here / Last Operand / End Program
Figure 6-3Flowchart For Multiplication Program 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 CTR - 8 P 0 E 0 AC Y cir EAC Y AC Cil EAC =0 =1 E X AC P P+X E 0 CTR CTR+1 AC X CTR Stop #0 =0
Table 6-15 Add Two Double Precision LDA AL /Load a Low ADD BL /Add B low ,Carry In E STA CL /Store in C Low CLA /Clear Ac CIL /Carry into Ac ADD Ah /A high and carry ADD BH /Add B high STA CH /Store in C High HLT AL, ____ /Location Of Operand AH, _____ BL, _____ BH, ______ CL, _______ CH, _________
Table 6-16 Demonstrates the use of subroutines Location 100 101 102 103 104 105 107 X, 108 Y, 109 SH4 10A 10B 10C 10D 10E 10F 110 MSK, /Main Program /Load X /Branch to Subroutine /Store shifted Number /Load Y /Branch To Subroutine /Store Shifted Number /Shift Left 4 Times /Store return Address here /Cir Left Once /Cir Left Forth Times /Set Ac(13—16) To Zero Return To Main Program /Mask Operand ORG 100 LDA X BSA SH4 STA X LDA Y BSA SH4 STA Y HLT HEX 1234 HEX 1234 HEX FFF0 CIL CIL CIL CIL AND MSK BUN SH4 HEX FFF0 END
Table 6-20Input pack to characters IN2, ________ /Subroutine entry FST, SKI BUN FST INP /Input first character OUT BSA SH4 /Shift 4 times BSA SH4 /Sift 4 more times SCD, SKI BUN SCD INP /Input second Character OUT BUN IN21 /Return
Table 6-21Program Input Character in a Buffer LDA ADS /LOAD IN BUFFER STA PTR /INITIALIZE POINTER BSA IN2 /GO IN IN2 STA PTR 1 / STORE IN BUFFER ISZ PTR / INCREMENT POINTER BUN LOP /INPUT MORE CHRACTER HLT HEX 500 /FIRST ADRESS OF BUFFER HEX 0 /LOCATION FOR POINTER. LOP, ADS, PTR,
Table 6-22 Compare Two Words LDA WD1 /LOAD FIRST WORD CMA INC /FORM 2’S COMPLEMENT ADD WD2 /ADD SECOND WORD SZA /SKIP IF AC IS ZERO BUN UEQ /UNEQUAL ROUTINE BUN EQL /EQUAL ROUTINE _____ _____ WD1, WD2,
Table 6-19Input-Output One Character (a) Input a Character: CIF, SKI /CHECK INPUT FLAG BUN CIF /FLAG=0 INP /FLAG=1 OUT /PRINT CHARACTER STA CHR /STORE CHARACTER HLT CHR, ____ /STORE CHARACTER (b) Output one character: LDA CHR /LOAD INTO AC COF, SKO /CHECK OUTPUT FLAG BUN COF /FLAG=0 OUT /FLAG=1 HLT CHR, HEX0057 /CHARACTER IS “W”
Table 6-23 program to service an Interrupt Location 0 ZERO, _______ /RETURN ADDRESS 1 BUN SRV /BRANCH ROUTINE 100 CLA /RUNING PROGRAM 101 ION /TURN ON FACILITY 102 LDA X 103 ADD Y /INTERRUPT HERE 104 STA Z /PROGRAM RETURN HERE . .. . .. /INTERRUPT ROUTINE S 200 SRV, STA SAC /STORE AC CIR /MOVE E INTO AC(1) STA SE /STORE OF E SKI /CHECK INPUT FLAG BUN NXT /FLAG IS OFF INP /FLAG IS ON OUT /PRINT FORM STA PT1 /STORE BUFFER ISZ PT1 /INC INPUT POINTER NXT, SKO /OUTPUT FLAG BUN EXT / FLAG IS OFF LDA PT2 1 /INC OUTPUT POINTER
Table 6-23program to service an Interrupt ISZ PT1 /INC INPUT POINTER LDA SE /RESERVE VALUE CIL /SHIFT IT TO E LDA SAC /RESTORE AC ION ZR0 1 /RETURN TO PROGRAM _____ /AC IS STORE HERE ______ /E IS STORED HERE _______ / POINTER OF INPUT BUFFER _________ /OUTPUT BUFFER EXT, SAC, SE, PT1 PT2,