Docsity

Translating High-Level Language to Assembler: Programming & Control Structures, Slides of Microprocessor and Interfacing

Partial preview of the text

Download Translating High-Level Language to Assembler: Programming & Control Structures and more Slides Microprocessor and Interfacing in PDF only on Docsity!

Lecture Overview

  • Programming structures
    • Translation of HLL structures to assembler
      • HLL = Higher Level Language
    • In line code
    • Conditional code statements
    • Loop control statements
    • Control Structures
    • Nested loops
  • REF: Chapter 4

Translation to Assembler

  • Common HLL structures
    • Straight line code โ€“ code to compute results
    • Loop code โ€“ code to establish a repetitive loop based on a count or condition
    • Decision code โ€“ code to direct execution flow to take one path or the other.
    • Nested Loops

Conditional Code Statements

  • Very few computational tasks involve simply a

unconditional sequence of tasks. In an

embedded system (the real world) there is always

a variability in the inputs or the data to be acted

on.

  • This gives rise to a couple of possible logical

constructs

  • IF a given condition is true THEN take a given action
  • IF a given condition is true THEN take a given action. Otherwise (ELSE) take and alternative action

The IF THEN structure

  • Graphical form of the

structure

  • HLL pseudocode
    • IF THEN
    • [process]
    • END
  • Generally the process is

straight inline code

Examples and translation

  • These HLL structures can be translated to assembler language
  • Example: compare the A and B accumulators. If A accum is less than B accum add 5 to A (BCD) and store in the variable result - STAB temp - IF A temp THEN - ADDA # - DAA - END - STAA result
  • Will come back to this after covering the remaining structures

Loop Structures

  • In programming there is typically the need to repeatedly perform an action until a condition is met.
  • These break down into two structures
    • REPEAT UNTIL structure
    • REPEAT note that action
    • [process] is performed at least once
    • UNTIL
    • DO WHILE structure
    • WHILE DO expression is
    • [process] evaluated before
    • END computation is done
    • (possible for no action)

Control Structures

  • Simple control structures are easy to translate
    • IS A = B or IS A>B
  • Consider the example from slide 8
    • IF A temp THEN
  • How does this translate to assembler
    • First compare the contents of A with temp
    • CMPA temp
    • This sets the CC register bits
    • BGE end jump over action for structure
    • so you want the complementary
    • condition if you are jumping over action
    • (go back and look at the structure)

Full assembler for example

  • temp RMB 1
  • result RMB 1
  • STAB temp
  • CMPA temp
  • BGE end
  • ADDA #
  • DAA
  • end STAA result

A coding

  • A possible coding for testing for
    • 3 < A < 12
  • The data A is in the A accumulator
    • CMPA #3 compare A to 3
    • BLE brout know A is > 3
    • CMPA #12 compare A to 12
    • BGE brout know A is >= 12
    • A in range so perform actions
    • brout the is the first instruction after test & action Docsity.com

Compound test coding

  • Coding for A < 5 AND B = 5
    • CMPA #
    • BGE outfail
    • CMPB #
    • BNE outfail
    • when you are here you know A<5 AND B=
    • outfail the label beyond the code for a TRUE
    • condition

The pseudocode algorithm

  • Algorithm to find value of unknown between 0 and 99. The pseudocode - Set guess = 100 and incr = 50 - WHILE guess NEQ unknown REPEAT - IF guess > unknown THEN - guess = guess โ€“ incr - incr = ceiling(incr/2) - ELSE - guess = guess + incr - incr = ceiling(incr/2) - ENDIF - ENDWHILE why no check for =?????

The coding

  • The code
    • ORG $
    • unknown FCB 47 set unknown value
    • guess RMB 1 location for guess var
    • incr RMB 1 location for increment var
    • ORG $C
    • LDAA #
    • STAA guess
    • LSRA divide by 2
    • STAA incr
    • LDAB incr
    • LSRB

Board work of algorithm

  • An example of the program in action will be

worked on the black board of the algorithm and coding.

  • Consider starting with unknown values of
    • 47
    • 31
    • 77
    • 8

Nested Loops

  • Decisions within decisions.
  • What is the error translating

to flow chart?

  • Fig 4.9 has error in B=4 decision should be B=