Download as pdf
Download as pdf
You are on page 1of 9
— CHAPTER SIX — Programming the Basic Computer IN THIS CHAPTER 68 Input-Ousput Programming 6-1 _Introduction ‘A total computer system includes both] As a consequence, there is 175 Scanned with CamScanner 176 es ta | : FABLES “Toc NASSAR EERRATEY we eps! in De 6 o provide an eaty reference for the programming examples that follow. Each instruction is assigned a threelewer symbol 10 f writing symbole ‘and Tap erage ‘written in any other language must be translated to the binary representation of inst y can be executed by the computer, Programs weit, ‘be in one of the following categories: of nstuctons and operands in bin tation of tmstrutions as they appear in cay 6-2__Machine Language ate Machines anaes instructions or statements for directing the computer to Scanned with CamScanner ‘machine language Stricily speaking, a mackine language program imple equivalency between binary and computer will execute these However, a person looking at this program wi standing what is o be achieved when this program the computer hardware recognizes only this ype o sesadecimal code program in Table in Table 6-1) instead of theie binary ep further and address by a symbelic address and each hexadecimal operand by a decimal operand Tis ‘TABLE 6-4 Program wth Symbolic Operation Codes Location Scanned with CamScanner 180 receded By a slash. a equivalent Fortran program for adding two integer numbers slit in Tible 6-6. The two values for Aand Bmay be specified by an input staemer ‘ ona of anignng hee memory locaton, one each fr aigead’ eddcnd: and sum, and ten deriving sequence of binary isco form the som, Thus a compler program, tanalats the symbol fb Fotsan program ni the binary vale ited inthe rogram of fable 62 TABLE 646 Foran Pogam wo Add Two Numbers INTEGER A, 8, C DATAAS3”BL-23 Crate END symbolic adress 63 Assembly Language ‘registers, The assembler converts the assembly language into machine language for execution, Roles of the Language Each ie of an assembly language progr i aranged in three columns cae ies The elds pele folowing informa L Oc gee cas cme 2 ne me field specifies a machine instruction oF a pseudoin- struct 3. ‘The Gmmifield may be empty or it may include a comment, cont of 8, t,o te bt not more than shee uplananen dara The pn ce aries ara Sema belaten or mum The mel Cn bees en pregame Aortic ed Tdistrnad oy eens y the assembler “The instruction eld in an assembly lang many aoa of the following items: SS ee Scanned with CamScanner ‘The following isan illustration ofthe symbols that may be placed inthe instruction field ofa program. z a cua non-MRI ADD OPR direct address MRI ADD PIRI indirect address MRI The fit three eter symbol in each ine must be one ofthe instruction sym bolt ofthe computer and mus be Isted in Table G1. A memory referee instruction, suchas ADD, must be followed by a symbole addres. The ete Tay or ray tbe present “Aeymbolic adress inthe instruction eld specifies the memory loane defined somewhere inthe program by slate an asem Hy language program toa binary program iis absoluly necessary hat cack syenbokc address thats mentioned in the instruction Bld must oct again ihelabel eld A pseueisructon gOTTRGHREHRERER bit rhe information about some phase ofthe translaon, Four itera rcogned by he ase send nie? Other asemblylnguage programs rcognse many mote prudlsew {OF The ORG forge pleudintracton lms the esemble at be itn operandi ie fllwing ine ob pad in «memory kw oie nanber next to ORG. Ire poe te ORG mae in a progra to specify more than one segment of memory. The than once by-step procedure taken by the program. Comments are mm purposes only and are neglected during the binary example of an assembly language program Scanned with CamScanner rnumbers be in theit 2's complement form. When the 2's complement of the sublrahend is taken (by complementing and incrementing the AC), verts to +23 and the dillerence is 83 + (2's complement of ~23) = 83 + 7Orgi of program action 100 192 compiler ated, the assemble cuted 100 times, each time witha diferent operand 100. — piler by going through the process of translating the program above tout assembly language program. A compiler may use an assembly language a ‘an intermediate step in the translation or may translate the program direct to binary. ‘The first statement in the Fortran program isa DIMENSION ‘This statement instructs the compiler to r=serve 100 words of memory for I0b ‘operands, The value of the operands is determined from an input (not listed in the program). The second statement informs the compiler th the numbers are integers. I they were of the real type, the compiler would have to reserve locations for Nloating point numbers and generate instructions i pseudoinstruction in line 18, which specifies the origin ofthe operands. The first and last operands are listed with a specific decimal number, although these values are not known during compilation. The compiler jus reserves be data space in memory and the values are inserted later when an input dat statement is executed. The line numbers in the symbolic program are for ret: erence only and are not part ofthe translated symbolic program, ORG 100 LDA ADS STAFTR Lor, ADDPTRI DECI /Last operand ‘The indexing of the DO statement is translated into Lhe instructions in thro the constants in ines af the counter reaches seo, the 100 operations wil be sera and the program will exit from the loop. e rine Some compilers wil want the statement SUM = 0 into a machine insteton tha ilies locaton SUM to zero, A reference tots eon, then made every Ume Foran salement umber 3s executed. Arner cg Tigent compiler will elie tht the sm can be formed in the accamot ny only the final in locaon SUM. This compiler will produce as insructon in ine 6 to clear the AG I wil also reserve memey macy Scanned with CamScanner a Se ec te om we See ms emcee ee Scanned with CamScanner to the HLT instruction, TABLE 6-18 Sabourin o Move a Blick of Data BUN LOP BUN MVE the loop will be executed many times before charac ferred into the accurmulator ) lists the instructions needed to print a characte ‘The characteris first loade then checked. IF 1s 0, the computer remains ing the fag bit. When the lag changes to 1, the accumulator tothe printer TABLE 619 Programs to Input and Oupus One Chanere HEM (0) Iaput a hance cr, Scanned with CamScanner Character Manipulation A computer is not just a calculator but al binary-coded char puter instructions may be to pack so ‘one IG-it word. The packed w sbroutine SH¢ (Table 6-16) i call for keeping track ofthe current em used in the program, so charac ‘or until the buffer reaches loca + location FFFF). Ina pr uation it may be necessary to ize ofthe buffer and a counter may be used for this purpose. Note that subroutine IN2 of Table 6-20 is called input and pack the two characters. In discussing the second pass of the assembler in Sec. G-t it was mee tioned that one of the most common operations of an table ookup. This is an operation that searches a table to find out if it eontains 2 rmbol wit search may be done by comparing the gi jen symbol The eet stored in the table. The search terminates when a match ‘each of the symbols ‘TABLE 6:20 Sebo t Input nd Pack Two Characters a In, = ‘Subroutine entry PST, SKI INP. Aap fet character BSASHS ——/ShifIefe four times INP. ‘Mapa second character BUNIN2I —_ /Retwen a2 UN ee ‘occurs or if none of the symbols match. When a match occurs, the assembler fever the equivalent binary value. A program for comparing two word sd in Table 6-22, The comparison is accomplished by forming the 2s ‘umber) and arthmetically adding it to the two words are equal and amatch occurs. not the same. This program can serve “The running time of input and output programs is made up pr time spent by the computer in waiting for the external device p that checks the flag keeps the computer occupied with atask : This waiting time can be eliminated ifthe terrupt is request from the external device. In the meantime, the computer can be busy performing other useful tasks. Obviously, ifno other program resides in mem: ‘ory, there is nothing for the computer to do, soit might as well check forthe TABLE 622 Progr to Compare Tro Words LDAWDI—/Load fit word INC ‘Form 2's complement ADD WD? /Add second word SZ ‘Skip f AGIs zero BUNUEQ —/Branch to “unequal” routine BUNEQL — /Braach w “equa” routine wo, = won Scanned with CamScanner

You might also like