Programming basic computer


Published on

Published in: Technology
1 Comment
  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Assembler is a software that converts assembly language program into binary language program
  • Why is a label terminated with a comma.
  • STRONT CONTESTANT FOR ...........................
  • Programming basic computer

    1. 1. Programming Basic Computer• The list of instructions or statements thatdirects the computer hardware to perform aspecific task is called a program.• There are many programming languages but,the computer basically understands programsthat are given in binary (0s, 1s) form. Thisimplies that all other programs should betranslated to binary before they can beexecuted by the computer..
    2. 2. Classification of Programs• Binary Code: These are instruction and data that are in 0sand 1s. They are stored in the computers main memory asthey do not need any conversions.• Octal / Hexadecimal code: These are codes or instructionsthat are in octal or hexadecimal representation.• Symbolic Code: This type of programming uses symbols(numbers, letters or special characters) in place of binarycode.• High level programming language: These are codes thatare directed at solving problems and not the details ofcomputer hardware behaviours. e.g. Java, C#, Pascal etc.They need special software called interpreter or compilerto convert them into binary code
    3. 3. Machine Language• These are programs that are written in binaryand stored directly in memory. The octal (3bits) or hexadecimal (4 bits) that can be easilyconverted to binary can also be referred to asmachine language.
    4. 4. Assembly Language• This uses symbols (English language words) towrite instructions. This is also a low levellanguage because of the one-to-onerelationship between symbolic instruction andits binary equivalent. The symbols are referredto as mnemonics. An assembler is a specialsoftware that converts assembly languageprogram into binary language program.
    5. 5. Basic symbols (mnemonics) ofassembly languageSymbol Example ExplanationAND AND A Perform AND logic operation on A with value of ACADD ADD A Add the value of variable A to AC, and carry bit to E flip flopLDA LDA M Load value of M into ACSTA STA M Store value of AC in MBUN BUN TT Branch unconditionally to location TTBSA BSA TT Save the return address in location TT and branch to TT+1ISZ ISZ T Increment T and skip next instruction (if T = 0)CLA CLA Clear Accumulator (AC)CLE CLE Clear ECMA CMA Complement AC (first complement)INC INC Increment ACSPA SPA Skip next instruction if AC is positiveSNA SNA Skip next instruction if AC is negativeHLT HLT Halt computer
    6. 6. Mnemonics of Assembly LanguageMnemonics Example ExplanationINP INP Get information from some input deviceOUT OUT Put information to some output deviceSKI SKI Skip next instruction if input flag is ONSKO SKO Skip next instruction if output flag is ONION ION Turn interrupt ONIOF IOF Turn interrupt OFFCALL CALL SUB Call subroutine which starts at location SUBRET RET Return to main programMOV MOV A, B Transfer the value of register B to register A
    7. 7. Pseudo instruction (AssemblerDirective)• These are false (pseudo) instructions that do not haveequivalent binary form but serve various functions. They donot refer to an operation that will be performed by theprogram during execution, rather it is a message to theassembler to help the assembler in the assembly process.E.g.• ORG T, T is the memory location where the first instructionof the program must be stored.• END, Specifies the end of the program• DEC T, T is a decimal number that needs to be convertedinto binary by the assembler• HEX T, T is a hexadecimal number that needs to beconverted into its equivalent binary using 4bits.
    8. 8. Rules of the Assembly Language• Each line of code must be divided into four fields.i.e. Label, instruction, operand & comment.• Label: This is a one to three alphanumericcharacters (symbolic address) that specifies thelocation of the instruction in memory. It shouldbe terminated with a comma (,) to enable theassembler recognize it as a label. The firstcharacter should be an alphabet and the resteither alphabets or numerals. A line with ORG orEND should not have a label.
    9. 9. Rules of the Assembly Language• A symbolic address in the instruction fieldshould specify the memory location of anoperand. This symbolic address must appearagain as a label, later in the program.• Instruction field. This specifies a mnemonic(pseudo) instruction.
    10. 10. Rules of the Assembly Language• Comment: Explains what each line of codedoes for easy understanding and explanation.Each comment must be preceded by /. Thishelps the assembler recognize the beginningof a program. It can be left empty.
    11. 11. Programming in Assembly Language• Write a program in assembly language to store15 at memory location TCode CommentORG 0 /Origin of the program in location zeroLDA A /Load operand (15) from ASTA T /Store operand (15) in memory location THLT /Halt computerA, DEC 15 /Decimal operand with value 15T DEC 0 /Value 15 will be stored at TEND /End of symbolic program
    12. 12. Programming in Assembly Language• Write a program in assembly language to addtwo decimal numbers (14 and -7) in memorylocations A and B.NB. We first have to bring the first operand toAC. Using the ADD instruction, we add thesecond operand with the content of AC. Theresult is then stored in AC. However to storethe result we use STA.
    13. 13. Programming in Assembly Language• . Label Code DescriptionORG 0 /Origin of program in location zeroBUN T /Branch unconditionally to location TLDA A /Load operand in accumulator from memorylocation AADD B /Add operand from memory location BSTA SUM /Store the sum in location SUMHLT /Halt ComputerA DEC 14 /Decimal operand with value 14B DEC -7 /Decimal operand with value -7SUM DEC 0 /Sum of A and B will be stored in AC, initial value ofSUM is 0END /End of symbolic program.
    14. 14. Flow chart• Flow chart for adding two decimal numbersSpecify the location where the program must be storedin memorySpecify the memory location of first operandSpecify the memory location of second operandAdd second operand with first operand , already in ACSpecify the memory location where the result from ACis to be storedLoad the first operand in AC
    15. 15. Assembly language to subtract twonumbers A – B (14 - 10)Label Code DescriptionORG 100 /Origin of program is 100LDA SUB /Load subtrahend to AC (B)CMA /Complement AC (-B)INC /Increment ACADD MIN /Add minuend to AC (A)STA DIF /Store the difference in memory location DIFHLT /Halt computerMIN, DEC 14 /Minuend with decimal 14 (A)SUB DEC 10 /Subtrahend with decimal 10 (B)DIF DEC 0 /Result of the difference is stored hereEND /End of symbolic program.
    16. 16. Flow chart for subtracting twonumbers A – B = A + (-B)Specify the memory location where the program must be storedSpecify memory location of subtrahend (B)Load the subtrahend in ACComplement value stored in ACIncrement value in AC by 1 (get - B)Specify location where minuend is stored in memory (A)Add the minuend to value in AC (A +(-B))Specify the location where the result will be stored in memoryCalculating2s complementThe negative of anumber is obtainedby calculating its2s complement. This isdone by adding 1 to its1s complement
    17. 17. Assembly language- Looping• Program loop (looping) is a sequence of instructionsthat are executed repeatedly, each time with adifferent set of data and the new result stored. E.g.2.....Int x, y;X = 10; y = 20;If (x<y)system.out.println(“x isless than y”);x = x +2;If (x == y)System.out.println(“now xis equal to y”);}}1)........Int x;X = 3;If (x < 10)x = x +1;elseSystem.out.println(x);}} x;for(x=0; x<10; x++)System.out.println (“x is:”+ x);}}
    18. 18. Program to add 50 numbers• To add 50 numbers we will have to uselooping by repeatedly performing addition (50times) with each of the 50 operands andstoring the result in AC each time. We assumethat the operands are stored in consecutivememory location so that we can get theoperand by incrementing the address
    19. 19. Assembly language program to add 50 numbersLine no Label Code Description1 ORG 50 /Origin of program is HEX 502 LDA ADS /Load address of first operand3 STA PTR /Store address in memory location called (PTR) pointer4 LDA NBR /Load -50 into AC5 STA CTR /Store the value in AC at CTR (counter)6 CLA /Clear accumulator7 LOP, ADD PTR I /Add an operand to AC8 ISZ PTR /Increment pointer9 ISZ CTR /Increment counter10 BUN LOP /Repeat loop again, AC gets nos added and store result11 STR SUM /Store sum12 HLT /Halt computer
    20. 20. Assembly language program to add 50 numbersLine no. Label Code Description13 ADS, HEX 50 /Address of first operand14 PTR, HEX 0 /Location reserved for pointer15 NBR, DEC -50 /Initialise counter16 CTR, HEX 0 /Location reserved for counter17 SUM, HEX 0 /Sum is stored here18 ORG 100 /Origin of operands is from memory location 10019 DEC 30 /First operand (i.e. 30)..68 DEC 14 /Last operand (50th number is 14)69 END /End of symbolic program
    21. 21. Flow chart for adding 100 numbers• .Specify the memory location where program is to be storedSpecify the memory location where the address of 1st operand is storedLoad this address into ACStore address (in AC) in a memory location. Let the location be PTRSimilarly, store -50 (counter variable) in a memory loc. called CTRSet AC 0Take address from PTR. Fetch the operand stored atthis address and add it to the value in ACIncrement PTR by 1Increment CTR by 1Is CTR = 0 ?Store the value in AC at location named SUMNoYes
    22. 22. Compute X+Y and store the result at Z(OR) Logic operations.Label Code DescriptionORG 0 /Origin of program at memory location 0LDA X /Load first operand aCMA /Complement A to get ĀSTA TMP /Store Ā in a temporary location TMPLDA Y /Load second operand BCMA /Complement B to get B̄AND TMP /AND with Ā to get Ā.B̄CMA /Complement (Ā.B̄) to get (A + B)HLT /Halt computerX, 1011 /First operand is stored hereY, 1000 /Second operand stored hereTMP, 0000 /Temporary location to store ĀEND
    23. 23. Flow chart for logic OR operationLoad X into ACComplement value in ACStore the value of AC in TMPLoad Y into ACComplement value in ACAND value with TMPComplement value in ACStore value of AC in Z
    24. 24. Imperative, Declarative and DirectiveStatements• Imperative statement. Indicates actions to be performedduring execution of the assembled program. E.g.LDA A, STA, ADD, ISZ C• Declarative statement. Declares constants or storagelocations or area in a program. E.gT DS 30declares a storage area of 30 words and indicates that thestorage area must be called T. T is the first word of theoperand. To access the 6th word for example, use T + 5.Alternative an index can be used. T(k) where k is the indexnumber of item to be accessed. E.g T(6) the seventhnumber as it starts from 0 i.e. T(0) is the first element.
    25. 25. Directive• Assembler directive statement, directs theassembler to take certain actions during theprocess of assembling a program. E.g. ORG’10’ indicates that the first word of theprogram must be placed at memory location‘10’. Also END indicates that no moreassembly language statements remain to beprocessed.
    26. 26. Program to show all codes.Label Code commentsORG 0 (Directive) /Store program at location 0LDA A (Imperative) /Load the value stored at memory locationASTA B (Imperative) /Store the value at A in the location BA DC ‘1500’ (Declarative) /Declare a constant 1500 named AB DS 1 (Declarative) /Declare a storage location called ‘B’capable of storing 1 wordEND (Directive) /End program