Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC 171 Introduction to Computer Science

Similar presentations


Presentation on theme: "CPSC 171 Introduction to Computer Science"— Presentation transcript:

1 CPSC 171 Introduction to Computer Science
Assembly Language and Assemblers

2 Machine Code Address Value 000000 1101 000101 000001 1101 000110
No natural language Difficult to change Data stored in binary

3 Assembly Language Symbolic Operations Symbolic Memory Addresses
Has Pseudo-operations for data generation

4

5 Structure of Assembly Code
Label: op-code symbol address label --comment

6 Example Assembly Code .begin loop: in x in y load x compare y
jumpgt done out x jump loop done: out y halt x: .data 0 y: .data 0 .end

7 op-code Symbol REF: page 248, Fig 6.5
Arithmetic OpCodes 0000 load 0001 store 0010 clear 0011 add 0100 increment 0101 subtract 0110 decrement I/0 OpCodes 1101 in 1110 out Logic/Control OpCodes 0111 compare 1000 jump 1001 jumpgt 1010 jumpeq 1011 jumplt 1100 jumpneq 1111 halt

8 Convert Pseudocode to Assembly code
1. Set NegCount to 0 2. Set I to 1 3. While I ≤ 5 do lines 4 through 6 4. Input a number, N 5. if N < 0 then increment NegCount 6. Increment I 7. End of loop 8. Output NegCount 9. Stop

9 Assembly Code .begin loop: load FIVE compare I jumpgt finish in N
load N compare NEG_ONE jumplt dont_add increment NegCount dont_add: jump loop finish: out NegCount halt NegCount: .data 0 I: .data 1 FIVE: .data 5 N: .data 0 NEG_ONE: .data -1 .end

10 You Try It Create Assembly Code for the following algorithm:
Get a number X Get a number Y If Y > X then print out Y Else print out X Stop


Download ppt "CPSC 171 Introduction to Computer Science"

Similar presentations


Ads by Google