Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter # 6 PROGRAMING THE BASIC COMPUTER.

Similar presentations


Presentation on theme: "Chapter # 6 PROGRAMING THE BASIC COMPUTER."— Presentation transcript:

1 Chapter # 6 PROGRAMING THE BASIC COMPUTER

2 Contents Machine language Assembly language The Assembler
Program Loops Programming Arithmetic and Logic Operations Subroutines Input-Output Programming

3 Table 6-1 Computer Instruction
Sym I= I=1 Description AND 0xxx 8xxx And Memory to AC ADD 1xxx 9xxx Add Memory to AC LDA 2xxx Axxx Load To AC STA 3xxx Bxxx Store Of AC BUN 4xxx Cxxx Branch Uncondionary BSA 5xxx Dxxx Return Address ISZ 6xxx Exxx Skip If Zero

4 CLA 7800 Clear AC Clear E Comp. AC Comp. E Cir. Right AC and E
Table 6-1 Instruction CLA 7800 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 CLE 7400 CMA 7200 CME 7100 CIR 7080 CIL 7040 INC 7020 SPA 7010 SNA 7008 SZA 7004 SZE 7002 HLT 7001

5 Instruction For Computer
INP F800 Input to AC OUT F400 Output From Ac SKI F200 Skip on Input Flag SKO F100 Skip On Output Flag ION F080 Interrupt On IOF F040 Interrupt Off

6 Table 6-4 Symbolic Operation Code
Location Instruction Comments LDA Load First operand In AC ADD Add second operand to Ac STA Store in location 006 HLT Halt Computer First Operand FFE Second Operand is Negative Store Sum Here

7 Table 6-3 Hexadecimal Add two Number
Location Instruction FFE9

8 Table 6-2 Binary to Add Two Numbers
Location Instruction Code

9 Table 6-5 Assembly Language Program
ORG Origin is 0 LDA A Load operation A ADD B Add operation B STA C Store Location C HLT Halt Computer A, DEC Decimal Operand B, DEC – Decimal Operand C, DEC Store in Location C END End Of Program

10 Table 6-6 Fortran Program to ADD Two Number
Integer A, B, C Data A, 83 B, -23 C = A+B End

11 Table 6-7 Definition 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

12 Instruction Field of Program
CLA NON-MRI ADD OPR DIRECT ADDRESS MRI ADD PTR I INDIRECT ADDRESS MRI

13 Table 6-8 Assembly language program subtract Two number
ORG 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 MINUEND SUB, DEC – SUMTRAHEND DIF, HEX DIFFERENCE STORE HERE END END PROGRAM

14 Table 6-9 translated program of table 6-8
HEXADECIMAL LOCATION CINTENT SYMBOLIC PROGRAM ORG 100 LDA SUB CMA INC ADD MIN STA DIF HLT MIN, DEC 83 FFE SUB, DEC -23 DIF, HEX0 END

15 ADDRESS SYMBOL HEXADECIMAL MIN 106 SUB 107 DIF 108
Address symbol Table ADDRESS SYMBOL HEXADECIMAL MIN SUB DIF

16 Table 6-11 line of code: pl3, ld,sub1
Memory word symbol hex-code binary represent 1 PL AC 2 3, C 3 L D C 4 A 5 SU 6 B 7 I CR OD

17 Figure 6-1 First pass of assembler
LC Scan line code Set LC Yes Label ORG No No Yes End Yes Store symbol in Address symbol With Ac Go to second pass No Increment LC

18 MEMORY SYMBOL HEX-CODE Binary rep.. WORD ( LC )
Table 6-12 Address symbol MEMORY SYMBOL HEX-CODE Binary rep.. WORD ( LC ) M I D N , E 2C (LC) S U B , C (LC) DI F C (LC)

19 Figure 6-2 Flowchart for second pass of assembler
LC DONE Scan next line of code Set LC yes yes Pseudo instruction ORG no END yes no DEC or HEX no yes MRI no Convert operand To binary and store In location Given by LC Get operation code and set bits 2-4 Valid Non-MRI instruction 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

20 Table 6-13 Program 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 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

21 Figure 6-3 Flowchart For Multiplication Program
X= Y= CTR P P E 0 AC Y cir EAC Y AC Cil EAC =0 =1 E X AC P P+X E CTR CTR+1 AC X CTR #0 =0 Stop

22 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, _________

23 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, ORG 100 LDA X BSA SH4 STA X LDA Y BSA SH4 STA Y HLT HEX 1234 /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 HEX FFF0 CIL CIL CIL CIL AND MSK BUN SH4 HEX FFF0 END

24 Table 6-20 Input pack to characters
IN2, ________ /Subroutine entry FST, SKI BUN FST INP /Input first character OUT BSA SH /Shift 4 times BSA SH4 /Sift 4 more times SCD, SKI BUN SCD INP /Input second Character BUN IN21 /Return

25 Table 6-21 Program Input Character in a Buffer
LDA ADS /LOAD IN BUFFER STA PTR /INITIALIZE POINTER BSA IN /GO IN IN2 STA PTR / STORE IN BUFFER ISZ PTR / INCREMENT POINTER BUN LOP /INPUT MORE CHRACTER HLT HEX /FIRST ADRESS OF BUFFER HEX /LOCATION FOR POINTER. LOP, ADS, PTR,

26 Table 6-22 Compare Two Words
LDA WD /LOAD FIRST WORD CMA INC /FORM 2’S COMPLEMENT ADD WD /ADD SECOND WORD SZA /SKIP IF AC IS ZERO BUN UEQ /UNEQUAL ROUTINE BUN EQL /EQUAL ROUTINE _____ WD1, WD2,

27 Table 6-19 Input-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 CHR, HEX /CHARACTER IS “W”

28 Table 6-23 program to service an Interrupt
Location ZERO, _______ /RETURN ADDRESS BUN SRV /BRANCH ROUTINE CLA /RUNING PROGRAM ION /TURN ON FACILITY LDA X ADD Y /INTERRUPT HERE 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 PT /STORE BUFFER ISZ PT /INC INPUT POINTER NXT, SKO /OUTPUT FLAG BUN EXT / FLAG IS OFF LDA PT /INC OUTPUT POINTER

29 Table 6-23 program to service an Interrupt
ISZ PT /INC INPUT POINTER LDA SE /RESERVE VALUE CIL /SHIFT IT TO E LDA SAC /RESTORE AC ION ZR /RETURN TO PROGRAM _____ /AC IS STORE HERE ______ /E IS STORED HERE _______ / POINTER OF INPUT BUFFER _________ /OUTPUT BUFFER EXT, SAC, SE, PT1 PT2,


Download ppt "Chapter # 6 PROGRAMING THE BASIC COMPUTER."

Similar presentations


Ads by Google