introduction to holtek asm programming. section-based programming relocatable segment of code/data...

27
Introduction to Holtek ASM Programming

Upload: albert-burke

Post on 30-Dec-2015

244 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Introduction to Holtek ASM Programming

Page 2: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Section-based Programming

• Relocatable segment of code/data

• Logical division of program

Page 3: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

section-1

section-2

section-3

Linker

Concept of Relocation

section-2

section-1

section-3

Page 4: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Name .section [alignment][combine]‘class’

defined by userreversed wordbyte / word / pageat addr / commoncode / data

Section Syntax

Name : .section :

alignment: combine:

class:

Page 5: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Directive Define Variable Data

name DB ?name DB repeated-count DUP(?)name DW ?name DW repeated-count DUP(?)name DBIT

Page 6: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Exampledata0 .section ‘data’var db ?array db 5 dup(?)var1 dw ?Array1 dw 3 dup(?)flag dbit

Page 7: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Directive Define Variable Data

Exampledata .section ‘data’mySTATUS label byte

C dbitAC dbitZ dbitOV dbit

name LABEL BYTEname DBIT

name DBIT

Page 8: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Directive Define Constant Data

[label:] DC expr1[,expr2[,..]]

must in code section

Example:

code .section ‘code’MyTable:

DC 0128h, 0ffh, 10h+20h

Page 9: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Directive ORG

ORG expression Relative to section beginningeg.

org 0ffhorg 10+20

Page 10: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Directive EQU

name EQU expression NOT variable definitioneg.

PortA EQU [12h]bmove EQU movTen EQU 10

Page 11: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Directive PROC/ENDP

PROC/ENDP

name PROC...(function body)...name ENDP

Page 12: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Directive END

END

...mov a,20hendmov a,10h ; ignored...

Page 13: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Directive PUBLIC & EXTERN

public name[,name].....code: labeldata: data defined by DB, DBIT

extern name:type[,name:type]....type: near, bit, byte

Page 14: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Example

extern var1: bytepublic func1

c2 .section 'code'func1 proc

mov a,var1add a,010hret

func1 endp

public var1extern func1:near

data .section at 40h 'data'var1 db ?

c1 .section at 0 'code'mov a,10hmov var1,acall func1jmp $

end

Page 15: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Directive MACRO/ENDM

name MACRO [param1[,param2]] LOCAL loc1,loc2 ... ... ENDM

Page 16: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

delay Macrolabel: EndM

.label:..label:.

delay Macro Local labellabel: EndM

Solution:

Multiple-defined labels in Macro Expansion

...

delay

...

delay

...

Page 17: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Example Macro

1 delay macro para12 local a13 a1:4 sdz para15 jmp a16 endm78 include ht48c30-1.inc9 data .section 'data'10 tmp1 db ?

11 code .section 'code'12 mov a,30h13 mov tmp1,a14 delay tmp115 delay tmp116 jmp $17 end

Page 18: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Directive Conditional

IFstatememts[ELSEstatements]ENDIF

IF expressionIFE expressionIFDEF nameIFNDEF name

Page 19: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Example Conditional Assembler1 include ht48c30.inc

2 _debug equ 13 code .section 'code'

4 ifdef _debug5 mov a,10h6 endif7 ifndef _debug8 mov a,20h9 endif

10 if _debug11mov a,30h12 endif13 ife _debug14mov a,40h15 endif16mov a,50h17add a,30h18jmp $

Page 20: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Directive File Control

.LIST

.NOLIST

.LISTMACRO

.NOLISTMACRO

.LISTINCLUDE

.NOLISTINCLUDE

MESSAGEINCLUDE

Page 21: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Directive Others

HIGH/LOW

OFFSET

SHR/SHL

Example:data .section 'data'array db 10 dup(?)code .section 'code'mov a,11111111b SHR 1 ;7fHmov a,0ffh AND 0fh ; 0fHmov a,offset array ; mov a,LOW 0abcdh ; cdHmov a,HIGH 0abcd ; abHjmp $

Page 22: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

routine .section page 'code'; input acc for index, ; output on ‘pattern’ ReadPattern PROC

add A,LOW OFFSET pattern_tablemov TBLP,Atabrdc pattern[0]mov A,TBLHmov pattern[1],Aret

ReadPattern ENDPpattern_table:

DC 2332h, 0232h, 1897h

used_data .section 'data'pattern DB 2 dup(?)

Example: Table Read

Page 23: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Bank (Organization)

ROM RAM

......

0H

1FFFH

0H

40H

FFH

BP76543210

Page 24: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Bank (Assignment)

Format:ROMBANK <bank> <sec1>,<sec2>,...

Example:ROMBANK 0 entry,mainROMBANK 1 routine

entry .section at 0 ‘code’main .section ‘code’routine .section ‘code’

Page 25: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Bank (Usage)

ROM

; modify BPMOV A, NewBPMOV BP, A

; JMP/CALL to switch bankJMP labelCALL func

; modify BPMOV A, NewBPMOV BP, A

; set MP1MOV A, BankOffsetMOV MP1, A

; read/write thr. R1MOV R1, AMOV A, R1

RAM

Page 26: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Listing File

• Find syntax error in MACRO/INCLUDE

• .listinclude .listmacro

• Macro nested level

• Offset relative to section

• Operand type:

external reference/relocatable name

Page 27: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program

Map file

• Result of section relocation

– Absolute starting address

– Length

• Public symbol

– sorted by name/offset

• What if source too big?