Programming basic computer

download Programming basic computer

of 26

  • date post

    21-Jun-2015
  • Category

    Technology

  • view

    274
  • download

    2

Embed Size (px)

Transcript of Programming basic computer

  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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