L11-HLL to Assembler - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

L11-HLL to Assembler

Description:

ECE 2560 L11-HLL to Assembler Department of Electrical and Computer Engineering The Ohio State University * ECE 3561 - Lecture 1 HLL to Assembler Pseudo HLL HLL ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 34
Provided by: JoanneE63
Category:
Tags: hll | assembler | l11

less

Transcript and Presenter's Notes

Title: L11-HLL to Assembler


1
L11-HLL to Assembler
ECE 2560
  • Department of Electrical and
  • Computer Engineering
  • The Ohio State University

2
HLL to Assembler
  • Pseudo HLL
  • HLL structure
  • Their flow chart
  • HHL code
  • Corresponding Assembler

3
What is Pseudo HLL
  • Pseudo HLL is a way of expressing an algorithm or
    procedure for performing a task.
  • Very similar to modern High Level programming
    Languages
  • Best illustrated with an example

4
Pseudo HLL example
  • Sum a list of 10 integers
  • 3 7 8 2 4 6 5 5 9 1
  • There are several methods
  • The algorithm here
  • Create sum and initialize to 0
  • Add first number
  • Repeat adding number until done with list

5
Pseudo HLL
  • Sequence of Actions
  • Do action A
  • Do action B
  • .
  • Do action Q

6
Decisions
  • Decision structures
  • IF condition THEN action if true
  • ELSE action if false
  • END IF
  • Example
  • Remove front bike wheel
  • TURN Bike over
  • IF wheel-has-quick-release-skewer
  • THEN flip level and remove wheel
  • ELSE use wrench to remove nuts from axle
  • remove wheel
  • END IF

7
Examples and demo
  • Example and demo of decision structures
  • IF THEN ELSE
  • Set up
  • Test condition
  • Branch to after the code
  • The action code

8
Example
  • Is a gt b ?
  • a and b are memory location labels
  • .data
  • a .word 0x00FF
  • b .word 0x00FF
  • The code if agtb THEN actions
  • cmp a,b computes b-a
  • but what jump?
  • after

9
The jumps
  • Jump Instructions
  • JC,Jump if carry set JHS,Jump if high or same
  • The C bit is tested
  • If set (i.e. 1) then the branch is taken
  • If clear, the next instruction is executed
  • JEQ, JZ Jump if equal, Jump if zero
  • The Z bit is tested
  • If set (i.e. 1) then the branch is taken
  • If clear, the next instruction is executed

10
The Jumps (2)
  • JGE Jump if greater or equal
  • The N and V bits are used
  • If N and V are set or reset (both 0 or both 1)
    the branch is taken
  • JL Jump if less
  • The N and V bits are used
  • If only one of N or V is set then the branch is
    taken
  • JMP Jump unconditionally

11
Jumps (3)
  • JN Jump is negative
  • The N bit is tested
  • If N is set (i.e. 1) the branch is taken
  • JNC Jump if carry not set
    JLO Jump is lower
  • The carry bit C is tested.
  • If C is 0 the branch is taken
  • JNE Jump not equal JNZ Jump if not zero
  • The Z bit is tested
  • If Z 0 the branch is taken

12
A test program
  • Write and compile a test program that sets up two
    values, uses cmp to compare them, and then runs
    through the branches.
  • Have values that are both positive, both
    negative, and one positive-one negative.

13
Adding the ELSE condition
  • If you have an else condition, set up the branch
    such that when the condition is not met, you have
    a label to branch to this code section.
  • cmp a,b
  • jge elsecond
  • THEN condition actions
  • jmp ifendpt
  • elsecond ELSE condition actions
  • Ifendpt following code

14
Repeat structures - Do Loops
  • Finite number of times DO LOOP
  • Set up any values for loop
  • FOR counter start TO end STEP x LOOP
  • actions of loop
  • END FOR
  • Example
  • Sum 0
  • FOR i 1 to 10 LOOP
  • Sum Sum element(i)
  • END FOR

15
A fix number of times
  • For I in 1 to 10 loop
  • action in loop
  • End loop
  • Assembler
  • Use a register for the current value of the loop
    counter
  • In data area have
  • stval the starting value, endval the ending
    value
  • .data
  • stval .word 0x0001
  • endval .word 0x000F loop 15 times

16
The structure
  • start of loop setup
  • mov stval,R8 i to R8
  • tol cmp R8,endval
  • jeq done
  • actions of loop
  • inc R8
  • jmp tol
  • done code after loop

17
Demo
  • Want to do loop 4 times
  • Setup stval of 1, endval of 4
  • But only execute the loop 3 times
  • Could you solve this with the type of branch?
    Difficult
  • Easy endval is number of times through the loop
    1 OR
  • i is one less than the iteration through the loop
    at compare, i.e. initial value is 0 move inc
    instruction to just after the jump

18
New material - TA
  • New material starts here

19
Repeat structures
  • Indeterminate number of times Repeat loop or
    decision loop action inside the loop causes
    condition to occur that ends the loop.
  • 2 structures
  • One has code that executes at least once
  • One has code that may or may not execute at all

20
While condition
  • While loop may or may not execute code
  • WHILE condition LOOP
  • SEQUENCE_of_ACTIONS
  • END loop
  • Example
  • WHILE not EOF LOOP
  • Read line from file
  • Process line
  • END LOOP

21
Repeat
  • Repeat Until structure
  • REPEAT
  • Sequence_of_statements
  • UNITL condition
  • Example - attempt to read will be done at least
    once
  • REPEAT
  • Read line from file
  • UNTIL EOF

22
Now what is the assembler?
  • For each of these Pseudo HLL structures what is
    the corresponding assembler.
  • Each will have assumption as to were data to be
    tested is.

23
Straight line code - Sequence
  • Straight line Pseudo HLL little modification is
    needed.
  • A mx b in Pseudo HLL
  • Where are values say in memory locations
    labeled by the same name
  • Code becomes
  • mov m,R8
  • push R8
  • push x
  • call smult
  • pop R8
  • pop R8
  • add b,R8
  • mov R8,A

24
Decision
  • Decision structure
  • IF condition THEN action if true
  • ELSE action if false
  • END IF
  • Example
  • IF (AltB) THEN tempA AB Btemp
  • END IF

25
Assembler for example
  • A and B are in memory
  • Will use a register for temp.
  • cmp A,B B-A is positive if AltB
  • jl noexch jump if BltA
  • mov A,R6
  • mov B,A
  • mov R6,B
  • noexch

26
A more efficient coding
  • Could be made a little more efficient
  • Previous code also exchanges when AB
  • cmp B,A A-B is negative if AltB
  • jge noexch jump if BltA
  • mov A,R6
  • mov B,A
  • mov R6,B
  • noexch

27
When there is an else
  • Else is similar to the previous code
  • IF (AltB) THEN tempA AB Btemp
  • ELSE A 0
  • END IF
  • Much like previous
  • cmp B,A A-B is negative if AltB
  • jge else jump if BltA
  • mov A,R6
  • mov B,A
  • mov R6,B
  • jmp after
  • else clr A
  • after

28
Repeat structures
  • Finite number of times DO LOOP
  • Set up any values for loop
  • FOR counter start TO end STEP x LOOP
  • actions of loop
  • END FOR
  • Example
  • Sum 0
  • FOR i 1 to 10 LOOP
  • Sum Sum element(i)
  • END FOR
  • How would this example be coded?

29
Coding for Do Loop
  • Where are control values?
  • i the current index value use R9
  • startval the starting value for i memory loc
  • endval the ending value for i memory
  • sum in memory
  • element label of list of values in memory
  • mov i,R9
  • tol cmp endval,R9 R9-endval
  • jge lpexit
  • mov R9,R8
  • dec R8
  • clrc
  • rolc R8
  • add element,R8
  • add _at_R8,sum
  • inc R9
  • jmp tol
  • lpexit

30
The repeat and while loops
  • The coding of the repeat and while loops is very
    similar.
  • Documents where variables are
  • Need loop control and testing of loop control
  • Which branch instruction to use takes some
    thought
  • Need to remember what the cmp instruction does!!

31
The while loop example
  • i0 flagTRUE
  • WHILE flag LOOP
  • increment i
  • Actions when value i
  • IF i 5 THEN flag False END IF
  • END LOOP
  • Now translate this to assembler

32
Assembler for while example
  • mov 0,i
  • mov 1,flag 1TRUE
  • rpt cmp flag,0
  • jeq done
  • inc i
  • nop code to do actions
  • cmp i,5
  • jne rpt
  • mov 0,flag
  • jmp rpt
  • done nop code after loop

33
Demo
  • Demo of loop code.
Write a Comment
User Comments (0)
About PowerShow.com