1 / 17

Computer Science 101

Computer Science 101 . Assembly Language. Problems with Machine Language. Uses binary - No English-like words to make it more readable Only numeric memory addresses - Can not name an instruction or data location

mahola
Download Presentation

Computer Science 101

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Science 101 Assembly Language

  2. Problems with Machine Language • Uses binary - No English-like words to make it more readable • Only numeric memory addresses - Can not name an instruction or data location • Difficult to change - If we leave out one instruction, all addresses from that point on will be incorrect. • Difficult to create data - Must use internal binary representation

  3. Assembly Language to the Rescue! • Symbolic operation codes: Load, Store, Jump, Compare, etc. • Symbolic names (user defined) for memory addresses Load Pay • Pseudo-operations provide services such as data generation.

  4. Assembler Assembly lang Source file Machine lang Object file Assembler • An assembler is a program that takes a source code program written in assembly language and converts it to a machine language object file. • Essentially a line by line translation.

  5. Labels: Giving names to locations. • We can attach a symbolic name to any instruction or data location by beginning the line with a label with that name. • A label consists of the name followed by a colon. • You use labels in all of the places that addresses would occur in machine language; i.e. you no longer use numeric addresses. • Address fields in instructions • Operands of computations • Targets of branch instructions

  6. Pseudo-operations • Pseudo-operations are not statements that are converted to machine code. They are used to request services of the assembler. Performed only when program assembled. • Hypothetical Machine Pseudo-Ops: All of the pseudo-ops begin with a period. .begin -- required to mark beginning .end -- required to mark end .data 30 -- puts a value at the memory location; value in decimal assembler converts to binary

  7. Example: Add X to Y and Store in ZZ = X + Y .begin load X add Y store Z halt X: .data 33 Y: .data 40 Z: .data 0 .end

  8. Developing Assembly Programs • First write your algorithm in pseudocode. • Then convert to assembly. • Convert computations using labeled memory locations and the register for variables - document these. • We’ll look at techniques for converting common control flow constructs to assembly language.

  9. Converting Set (Assignment) Statements • Set <variable> to <expression> • Semantics: Compute value of the expression Give this value to the variable • Assembly language: Accumulate value of expression in R Store the value in the variable’s location

  10. Example • Set X to 2Y + Z – 5 • load Y add Y add Z subtract FIVE store X …X: .data 0Y: .data 20Z: .data 30FIVE: .data 5…

  11. If XY then Statements AStatements B load X compare Y jumpgtBSpot …Translation of A ... BSpot: …Translation of B Converting If-statements T Cond A Code F B Code

  12. User inputs number. If number is greater than 5 we output the number. Pseudocode: Get N If N>5 then Print N Stop .begin in N load N compare FIVE jumpgt DONE jumpeq DONE out N DONE: halt N: .data 0 FIVE: .data 5 .end If-statement example

  13. If XY then Statements A else Statements B Statements C load X compare Y jumpgt Else …Translation of A ... Else: …Translation of B … …Translation of C jump CSpot CSpot: Converting If-else-statements F T Cond BCode A Code C Code

  14. While XY Do Statements A Statements B load X compare Y jumpgt BSpot …Translation of A ... BSpot: …Translation of B … WHILE: jump WHILE Converting While-statements T Cond A Code F B Code

  15. Program outputs sum of 10 numbers entered by the user. Pseudocode: Set Ct to 10 Set Sum to 0 While Ct>0 Get Num Set Sum to Sum+Num Set Ct to Ct-1 Print Sum Stop .begin load TEN store CT clear SUM WHILE: load CT compare ZERO jumpeq PRNT in NUM load NUM add SUM store SUM decrement CT jump WHILE PRNT: out SUM halt While-statement example

  16. .begin load TEN store CT clear Sum WHILE: load CT compare ZERO jumpeq PRNT in NUM load NUM add SUM store SUM decrement CT jump WHILE PRNT: out SUM halt TEN: .data 10 CT: .data 0 SUM: .data 0 NUM: .data 0 ZERO: .data 0 .end While-statement example (cont.)

  17. Cows, horses, supplies,... Man, I can't keep track of everything!

More Related