Assembly Language - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Assembly Language

Description:

We are using memory location 0x25 to store a value that we want to load into accumulator A ... Finally, store the length in memory and come to a stop (sort of) ... – PowerPoint PPT presentation

Number of Views:69
Avg rating:3.0/5.0
Slides: 12
Provided by: ROTH8
Category:

less

Transcript and Presenter's Notes

Title: Assembly Language


1
Assembly Language
  • We can use our current knowledge of the HC11 to
    hand assemble a program
  • Select operation
  • Select instruction mode
  • Get opcode from table
  • Determine operands
  • etc.
  • This is a laborious process
  • Some simple tools will make programming at this
    low level much more effective
  • Some notion of variables (labels)
  • Automatic lookup of opcode from table
  • Rather use mnemonic of operation

2
Example
  • We are using memory location 0x25 to store a
    value that we want to load into accumulator A
  • Hand assemble
  • Look up opcode for direct (or extended) mode load
    the accumulator 0x96
  • Determine operand 0x25 in this case
  • 0x96 0x25
  • Easier to
  • LDAA 0x25
  • Even better to
  • define myvar 0x25
  • LDAA myvar

3
Assembly With Mnemonics
  • For the most part, very straightforward
  • Operations with only one addressing mode can be
    referred to with mnemonic without confusion.
  • Inherent, Relative
  • Operations with multiple addressing modes need
    help
  • LDAA 0x25 ? immediate mode loads 0x25 into A
  • LDAA 0x25 ? direct mode load whatever is in
    address 0x0025 into A
  • LDAA 0x1425 ? extended mode load whatever is in
    address 0x1425
  • LDAA 0x03,x ? indexed with X
  • LDAA 0x03,y ? indexed with X
  • Some assemblers get confused
  • LDAA 0x0025 ? direct or extended?
  • Should automatically optimize. Some do, some do
    not.
  • forces direct mode GNU.
  • LDAA 0x25
  • Mostly an issue when labels are used (up next).

4
Labels a.k.a Symbols
  • Act as variables and/or placeholders in assembly
    source
  • Resolved during assembly
  • Properties of Regular Labels GNU
  • Not limited in length
  • Must be unique in source file
  • Must be unique in project if made global
  • Must begin with A-Z a-z . _
  • Subsequent characters 0-9 A-Z a-z _
  • Colon terminates ()

5
Local Labels GNU
  • Primarily used for branches
  • 1 to maxPositiveInteger
  • Scope
  • Back to same label or beginning of file
  • Forward to same label or end of file
  • Must specify whether you want the
  • Next (f forward) matching label
  • Previous (b backward) one
  • If no fb, number is interpreted as a relative
    addressing mode offset.

6
Sections
  • A type of label that identifies a section or
    range of memory
  • .section name
  • Standard sections GNU
  • .bss uninitialized mutable data (block started
    by symbol
  • .data initialized mutable data
  • .rodata initialized read-only data
  • .text code

7
Data Storage
  • Directives can follow label declarations to
    create data elements
  • label directive data , data,
  • Reserve but do not initialize
  • Byte .space N, .rmb N
  • Word .ds N
  • Reserve and initialize
  • Byte .byte 0x01, , .fcb 0x05,
  • Word .word 0x1234,
  • String
  • .ascii string stores characters
  • .asciz string stores characters plus null
    terminator
  • Data in .bss will not be initialized, that is, it
    will not be included in download image, even if
    you use .byte, .word, etc.

8
A Couple More Directives
  • .global label create a global label
  • For linking multiple modules
  • Linker will be looking for a global label
    _start to know where to start execution GNU
  • .include name include another source file
  • sets off a comment to the end of the line
  • Note, works with labels as well
  • LDAA mydata ? loads whatever value mydata is
  • LDAA mydata ? loads whatever value is stored at
    address mydata

9
  • MAXLEN 128
  • .section .bss bss uninitialized data --
    maps data section
  • (starting at 0xF000) per fox11w.x
  • length .short 1 reserve a 16-bit word for
    the length (uninitialized)
  • .section .rodata
  • string .asciz "Testing... one... two...
    three..."
  • .section .text
  • .global _start exported entry point expected
    by GNU as
  • _start
  • Set up string pointer and counter
  • ldx string pointer to string
  • ldy 0 count of non-null
    characters

10
Listing File
  • lab1.elf file format elf32-m68hc11
  • Contents of section .text
  • 8400 ce841c18 ce00006d 00270b18 08188c00
    .......m.'......
  • 8410 80270308 20f118ff f00020fe .'..
    ..... .
  • Contents of section .rodata
  • 841c 54657374 696e672e 2e2e206f 6e652e2e
    Testing... one..
  • 842c 2e207477 6f2e2e2e 20746872 65652e2e .
    two... three..
  • 843c 2e00
  • ..
  • Disassembly of section .text
  • 00008400 lt_startgt
  • 8400 ce 84 1c ldx 841c lt_etextgt
  • 8403 18 ce 00 00 ldy 0 lt__data_section_size
    gt
  • 8407 6d 00 tst 0,x
  • 8409 27 0b beq 8416 lt_start0x16gt
  • 840b 18 08 iny
  • 840d 18 8c 00 80 cpy 80 ltMAXLENgt

11
Questions
Write a Comment
User Comments (0)
About PowerShow.com