Download presentation
1
Introduction to Holtek ASM Programming
2
Section-based Programming
Relocatable segment of code/data Logical division of program
3
Concept of Relocation Linker section-1 section-2 section-1 section-2
4
Section Syntax Name : .section : alignment: combine: class:
defined by user reversed word byte / word / page at addr / common code / data
5
Directive Define Variable Data
name DB ? name DB repeated-count DUP(?) name DW ? name DW repeated-count DUP(?) name DBIT
6
Example data0 .section ‘data’ var db ? array db 5 dup(?) var1 dw ? Array1 dw 3 dup(?) flag dbit
7
Directive Define Variable Data
name LABEL BYTE name DBIT Example data .section ‘data’ mySTATUS label byte C dbit AC dbit Z dbit OV dbit
8
Directive Define Constant Data
[label:] DC expr1[,expr2[,..]] must in code section Example: code .section ‘code’ MyTable: DC 0128h, 0ffh, 10h+20h
9
Directive ORG ORG expression Relative to section beginning eg.
org 0ffh org 10+20
10
Directive EQU name EQU expression NOT variable definition eg.
PortA EQU [12h] bmove EQU mov Ten EQU 10
11
Directive PROC/ENDP PROC/ENDP name PROC ... (function body) name ENDP
12
Directive END END ... mov a,20h end mov a,10h ; ignored
13
Directive PUBLIC & EXTERN
public name[,name]..... code: label data: data defined by DB, DBIT extern name:type[,name:type].... type: near, bit, byte
14
Example public var1 extern func1:near data .section at 40h 'data'
var1 db ? c1 .section at 0 'code' mov a,10h mov var1,a call func1 jmp $ end extern var1: byte public func1 c2 .section 'code' func1 proc mov a,var1 add a,010h ret func1 endp
15
Directive MACRO/ENDM
name MACRO [param1[,param2]] LOCAL loc1,loc2 ... ENDM
16
Multiple-defined labels in Macro Expansion
delay Macro label: EndM Solution: delay Macro Local label label: EndM ... delay . label: . label:
17
Example Macro 1 delay macro para1 2 local a1 3 a1: 4 sdz para1
5 jmp a1 6 endm 7 8 include ht48c30-1.inc 9 data .section 'data' 10 tmp1 db ? 11 code .section 'code' 12 mov a,30h 13 mov tmp1,a 14 delay tmp1 15 delay tmp1 16 jmp $ 17 end
18
Directive Conditional
IF statememts [ELSE statements] ENDIF IF expression IFE expression IFDEF name IFNDEF name
19
Example Conditional Assembler
1 include ht48c30.inc 2 _debug equ 1 3 code .section 'code' 4 ifdef _debug 5 mov a,10h 6 endif 7 ifndef _debug 8 mov a,20h 9 endif 10 if _debug 11 mov a,30h 12 endif 13 ife _debug 14 mov a,40h 15 endif 16 mov a,50h 17 add a,30h 18 jmp $
20
Directive File Control
.LIST .NOLIST .LISTMACRO .NOLISTMACRO .LISTINCLUDE .NOLISTINCLUDE MESSAGE INCLUDE
21
Directive Others HIGH/LOW OFFSET SHR/SHL Example:
data .section 'data' array db 10 dup(?) code .section 'code' mov a, b SHR 1 ;7fH mov a,0ffh AND 0fh ; 0fH mov a,offset array ; mov a,LOW 0abcdh ; cdH mov a,HIGH 0abcd ; abH jmp $
22
Example: Table Read routine .section page 'code'
; input acc for index, ; output on ‘pattern’ ReadPattern PROC add A,LOW OFFSET pattern_table mov TBLP,A tabrdc pattern[0] mov A,TBLH mov pattern[1],A ret ReadPattern ENDP pattern_table: DC 2332h, 0232h, 1897h used_data .section 'data' pattern DB 2 dup(?)
23
Bank (Organization) ROM RAM 0H 0H 40H ... ... 1FFFH FFH BP
24
Bank (Assignment) Format:
ROMBANK <bank> <sec1>,<sec2>,... Example: ROMBANK 0 entry,main ROMBANK 1 routine entry .section at 0 ‘code’ main .section ‘code’ routine .section ‘code’
25
Bank (Usage) ROM RAM ; modify BP MOV A, NewBP MOV BP, A
; JMP/CALL to switch bank JMP label CALL func ; modify BP MOV A, NewBP MOV BP, A ; set MP1 MOV A, BankOffset MOV MP1, A ; read/write thr. R1 MOV R1, A MOV A, R1
26
Listing File Find syntax error in MACRO/INCLUDE
.listinclude .listmacro Macro nested level Offset relative to section Operand type: external reference/relocatable name
27
Map file Result of section relocation Public symbol
Absolute starting address Length Public symbol sorted by name/offset What if source too big?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.