Instructor: Nachiket M' Kharalkar - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Instructor: Nachiket M' Kharalkar

Description:

pull removes data from the top of the stack. stack implements last in first out (LIFO) behavior ... puly pull from stack into Y. ins S=S 1 (discard top of stack) ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 18
Provided by: nachiketk
Category:

less

Transcript and Presenter's Notes

Title: Instructor: Nachiket M' Kharalkar


1
Introduction to Microcontrollers
  • Instructor Nachiket M. Kharalkar
  •  
  • Lecture 8
  • Date 06/18/2007
  • E-mail knachike_at_ece.utexas.edu
  •  

2
Todays Agenda
  • Exam 1 June 25th
  • Stack
  • Assembly language development process
  • Switch LED interface
  • Quiz 1

3
Lab 2 demo
4
Shift operations
  • The N bit is set if the result is negative.
  • The Z bit is set if the result is zero.
  • The V bit is set on a signed overflow, change in
    the sign bit.
  • The C bit is the carry out after the shift.
  • asla RegARegA2 (same as lsla)
  • aslb RegBRegB2 (same as lslb)
  • asld RegDRegD2 (same as lsld)
  • lsla RegARegA2 (same as asla)
  • lslb RegBRegB2 (same as aslb)
  • lsld RegDRegD2 (same as asld)
  • asra RegARegA/2 (signed)
  • asrb RegBRegB/2 (signed)
  • asrd RegDRegD/2 (signed)
  • lsra RegARegA/2 (unsigned)
  • lsrb RegBRegB/2 (unsigned)
  • lsrd RegDRegD/2 (unsigned)
  • rola RegArol(RegA) (C?A7??A0?C)
  • rolb RegBrol(RegB) (C?B7??B0?C)
  • rora RegAror(RegA) (C?A7??A0?C)

5
Friendly software
  • Set bit 2 of port T
  • ldaa 00000100
  • oraa PTT
  • staa PTT
  • Clear bit 5 of port AD
  • ldaa 11011111
  • anda PTAD
  • staa PTAD

6
Subroutines and the stack
  • classical definition of the stack
  • push saves data on the top of the stack,
  • pull removes data from the top of the stack
  • stack implements last in first out (LIFO)
    behavior
  • stack pointer (SP) points to top element
  • many uses of the stack
  • temporary calculations
  • subroutine (function) return addresses
  • subroutine (function) parameters
  • local variables

7
ldaa 1 psha
lds 4000
ldaa 2 psha
ldaa 3 psha
pulb
8
  • The push and pull instructions
  • psha push Register A on the stack
  • pshb push Register B on the stack
  • pshx push Register X on the stack
  • pshy push Register Y on the stack
  • des S S-1 (reserve space)
  • pula pull from stack into A
  • pulb pull from stack into B
  • pulx pull from stack into X
  • puly pull from stack into Y
  • ins SS1 (discard top of stack)
  • The following are important transfer instructions
  • tsx transfer S to X
  • tsy transfer S to Y
  • txs transfer X to S

9
We use the term subroutine all functions or
procedures
  • whether or not they return a value
  • develop modular software
  • called by either bsr or jsr
  • subroutine returns using rts

10
  • org 4000
  • main lds 4000 initialize stack
  • clra
  • loop bsr sub branch to subroutine
  • bra loop
  • Purpose increment a number
  • Input RegA, range 0 to 255
  • Output RegAInput1
  • Errors Will overflow if input is 255
  • sub inca adds one to Input
  • rts
  • org fffe
  • fdb main

11
Execution of the bsr instruction
  • Opcode fetch R 0x4004 0x07 from EEPROM
  • Operand fetch R 0x4005 0x02 from EEPROM
  • Stack store lsbW 0x3FFF 0x06 to RAM
  • Stack store msbW 0x3FFE 0x40 to RAM

12
The stack before and after execution of the bsr
instruction
13
Execution of the rts instruction
  • Opcode fetch R 0x4009 0x3D from EEPROM
  • Stack read msb R 0x3FFE 0x40 from RAM
  • Stack read lsb R 0x3FFF 0x06 from RAM

14
The stack before and after execution of the rts
instruction
15
Assembly language development process
16
Assembly steps
  • The first pass
  • check for syntax errors
  • size of each line of object code
  • create the symbol table
  • The second pass
  • check for syntax errors, errors reported in
    listing file
  • create object code, S19 file if needed for real
    6812
  • recreate the symbol table, phasing error if
    different
  • put object code, details and source into listing
    file
  • add symbol table to the end of the listing file
  • A symbol table is a mapping between symbolic
    names
  • PTT equals 0240

17
Errors that occur during the assembly process
  • 1) Label previously defined error label occurs
    multiple times
  • 2) Undefined opcode error operation does not
    exist
  • 3) Operand error syntax error within the operand
  •      expression error
  •      undefined symbol in expression
  •      addressing mode error
  • size of allocated storage too big, e.g., ds
    1001000
  • 4) Phasing error value of symbol changes from
    pass1 to pass2
  • 5) Can't program address error
  • 6) Branch too far error destination address is
    too far away
  • 7) Illegal string termination e.g., "Hello
    World!
Write a Comment
User Comments (0)
About PowerShow.com