Introduction to Holtek ASM Programming Sectionbased Programming Relocatable

Introduction to Holtek ASM Programming

Section-based Programming • • Relocatable segment of code/data Logical division of program

Concept of Relocation section-1 section-2 section-3 section-2 Linker section-1 section-3
![Section Syntax Name. section [alignment][combine]‘class’ Name : . section : alignment: combine: class: defined Section Syntax Name. section [alignment][combine]‘class’ Name : . section : alignment: combine: class: defined](http://slidetodoc.com/presentation_image_h2/55ad1d5d71f82960ad478ec46ec2b0a6/image-4.jpg)
Section Syntax Name. section [alignment][combine]‘class’ Name : . section : alignment: combine: class: defined by user reversed word byte / word / page at addr / common code / data

Directive Define Variable Data name name DB ? DB repeated-count DUP(? ) DW ? DW repeated-count DUP(? ) DBIT

Example data 0. section ‘data’ var db ? array db 5 dup(? ) var 1 dw ? Array 1 dw 3 dup(? ) flag dbit

Directive Define Variable Data name LABEL BYTE name DBIT Example data. section ‘data’ my. STATUS label byte C dbit AC dbit Z dbit OV dbit
![Directive Define Constant Data [label: ] DC expr 1[, expr 2[, . . ]] Directive Define Constant Data [label: ] DC expr 1[, expr 2[, . . ]]](http://slidetodoc.com/presentation_image_h2/55ad1d5d71f82960ad478ec46ec2b0a6/image-8.jpg)
Directive Define Constant Data [label: ] DC expr 1[, expr 2[, . . ]] must in code section Example: code. section ‘code’ My. Table: DC 0128 h, 0 ffh, 10 h+20 h

Directive ORG expression Relative to section beginning eg. org 0 ffh org 10+20
![Directive EQU name EQU expression NOT variable definition eg. Port. A EQU [12 h] Directive EQU name EQU expression NOT variable definition eg. Port. A EQU [12 h]](http://slidetodoc.com/presentation_image_h2/55ad1d5d71f82960ad478ec46ec2b0a6/image-10.jpg)
Directive EQU name EQU expression NOT variable definition eg. Port. A EQU [12 h] bmove EQU mov Ten EQU 10

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

Directive END. . . mov a, 20 h end mov a, 10 h ; ignored. . .
![Directive PUBLIC & EXTERN public name[, name]. . . code: label data: data defined Directive PUBLIC & EXTERN public name[, name]. . . code: label data: data defined](http://slidetodoc.com/presentation_image_h2/55ad1d5d71f82960ad478ec46ec2b0a6/image-13.jpg)
Directive PUBLIC & EXTERN public name[, name]. . . code: label data: data defined by DB, DBIT extern name: type[, name: type]. . type: near, bit, byte

Example public var 1 extern func 1: near data. section at 40 h 'data' var 1 db ? c 1. section at 0 'code' mov a, 10 h mov var 1, a call func 1 jmp $ end extern var 1: byte public func 1 c 2. section 'code' func 1 proc mov a, var 1 add a, 010 h ret func 1 endp
![Directive MACRO/ENDM name MACRO [param 1[, param 2]] LOCAL loc 1, loc 2. . Directive MACRO/ENDM name MACRO [param 1[, param 2]] LOCAL loc 1, loc 2. .](http://slidetodoc.com/presentation_image_h2/55ad1d5d71f82960ad478ec46ec2b0a6/image-15.jpg)
Directive MACRO/ENDM name MACRO [param 1[, param 2]] LOCAL loc 1, loc 2. . . ENDM

Multiple-defined labels in Macro Expansion delay label: Macro End. M . . . delay. . . Solution: delay Macro . label: . Local label: End. M

Example Macro 1 2 3 4 5 6 7 8 9 10 delay macro para 1 local a 1: sdz para 1 jmp a 1 endm include ht 48 c 30 -1. inc data. section 'data' tmp 1 db ? 11 code. section 'code' 12 mov a, 30 h 13 mov tmp 1, a 14 delay tmp 1 15 delay tmp 1 16 jmp $ 17 end
![Directive Conditional IF statememts [ELSE statements] ENDIF IF expression IFE expression IFDEF name IFNDEF Directive Conditional IF statememts [ELSE statements] ENDIF IF expression IFE expression IFDEF name IFNDEF](http://slidetodoc.com/presentation_image_h2/55ad1d5d71f82960ad478ec46ec2b0a6/image-18.jpg)
Directive Conditional IF statememts [ELSE statements] ENDIF IF expression IFE expression IFDEF name IFNDEF name

Example Conditional Assembler 1 include ht 48 c 30. inc 2 _debug equ 1 3 code. section 'code' 4 ifdef _debug 5 mov a, 10 h 6 endif 7 ifndef _debug 8 mov a, 20 h 9 endif 10 if _debug 11 mov a, 30 h 12 endif 13 ife _debug 14 mov a, 40 h 15 endif 16 mov a, 50 h 17 add a, 30 h 18 jmp $

Directive File Control. LIST. NOLISTMACRO. LISTINCLUDE. NOLISTINCLUDE MESSAGE INCLUDE

Directive Others HIGH/LOW OFFSET SHR/SHL Example: data. section 'data' array db 10 dup(? ) code. section 'code' mov a, 1111 b SHR 1 ; 7 f. H mov a, 0 ffh AND 0 fh ; 0 f. H mov a, offset array ; mov a, LOW 0 abcdh ; cd. H mov a, HIGH 0 abcd ; ab. H jmp $

Example: Table Read routine. section page 'code' ; input acc for index, ; output on ‘pattern’ Read. Pattern PROC add A, LOW OFFSET pattern_table mov TBLP, A tabrdc pattern[0] mov A, TBLH mov pattern[1], A ret Read. Pattern ENDP pattern_table: DC 2332 h, 0232 h, 1897 h used_data. section 'data' pattern DB 2 dup(? )

Bank (Organization) ROM RAM 0 H 0 H 40 H . . . 1 FFFH BP 76543210

Bank (Assignment) Format: ROMBANK <bank> <sec 1>, <sec 2>, . . . Example: ROMBANK 0 entry, main ROMBANK 1 routine entry. section at 0 ‘code’ main. section ‘code’ routine. section ‘code’

Bank (Usage) ROM RAM ; modify BP MOV A, New. BP MOV BP, A ; JMP/CALL to switch bank JMP label CALL func ; set MP 1 MOV A, Bank. Offset MOV MP 1, A ; read/write thr. R 1 MOV R 1, A MOV A, R 1

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?
- Slides: 27