Post on 30-Dec-2015
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
Name .section [alignment][combine]‘class’
defined by userreversed wordbyte / word / pageat addr / commoncode / data
Section Syntax
Name : .section :
alignment: combine:
class:
Directive Define Variable Data
name DB ?name DB repeated-count DUP(?)name DW ?name DW repeated-count DUP(?)name DBIT
Exampledata0 .section ‘data’var db ?array db 5 dup(?)var1 dw ?Array1 dw 3 dup(?)flag dbit
Directive Define Variable Data
Exampledata .section ‘data’mySTATUS label byte
C dbitAC dbitZ dbitOV dbit
name LABEL BYTEname DBIT
name DBIT
Directive Define Constant Data
[label:] DC expr1[,expr2[,..]]
must in code section
Example:
code .section ‘code’MyTable:
DC 0128h, 0ffh, 10h+20h
Directive ORG
ORG expression Relative to section beginningeg.
org 0ffhorg 10+20
Directive EQU
name EQU expression NOT variable definitioneg.
PortA EQU [12h]bmove EQU movTen EQU 10
Directive PROC/ENDP
PROC/ENDP
name PROC...(function body)...name ENDP
Directive END
END
...mov a,20hendmov a,10h ; ignored...
Directive PUBLIC & EXTERN
public name[,name].....code: labeldata: data defined by DB, DBIT
extern name:type[,name:type]....type: near, bit, byte
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
Directive MACRO/ENDM
name MACRO [param1[,param2]] LOCAL loc1,loc2 ... ... ENDM
delay Macrolabel: EndM
.label:..label:.
delay Macro Local labellabel: EndM
Solution:
Multiple-defined labels in Macro Expansion
...
delay
...
delay
...
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
Directive Conditional
IFstatememts[ELSEstatements]ENDIF
IF expressionIFE expressionIFDEF nameIFNDEF name
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 $
Directive File Control
.LIST
.NOLIST
.LISTMACRO
.NOLISTMACRO
.LISTINCLUDE
.NOLISTINCLUDE
MESSAGEINCLUDE
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 $
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
Bank (Organization)
ROM RAM
......
0H
1FFFH
0H
40H
FFH
BP76543210
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’
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
Listing File
• Find syntax error in MACRO/INCLUDE
• .listinclude .listmacro
• Macro nested level
• Offset relative to section
• Operand type:
external reference/relocatable name
Map file
• Result of section relocation
– Absolute starting address
– Length
• Public symbol
– sorted by name/offset
• What if source too big?