280 likes | 636 Views
Introduction to Holtek ASM Programming. Section-based Programming. Relocatable segment of code/data Logical division of program. section-1. Concept of Relocation. section-1. section-2. section-2. Linker. section-3. section-3. Section Syntax.
E N D
Section-based Programming • Relocatable segment of code/data • Logical division of program
section-1 Concept of Relocation section-1 section-2 section-2 Linker section-3 section-3
Section Syntax Name.section [alignment][combine]‘class’ Name : .section : alignment: combine: class: defined by user reversed word byte / word / page ataddr / common code / data
Directive Define Variable Data name DB ? name DB repeated-count DUP(?) name DW ? name DW repeated-count DUP(?) name DBIT
Example data0 .section ‘data’ var db ? array db 5 dup(?) var1 dw ? Array1 dw 3 dup(?) flag dbit
Directive Define Variable Data name LABEL BYTE name DBIT name DBIT Example data .section ‘data’ mySTATUS label byte C dbit AC dbit Z dbit OV 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 beginning • eg. • org 0ffh • org 10+20
Directive EQU • name EQU expression • NOT variable definition • eg. • PortA EQU [12h] • bmove EQU mov • Ten EQU 10
Directive PROC/ENDP • PROC/ENDP • name PROC • ... • (function body) • ... • name ENDP
Directive END END ... mov a,20h end mov a,10h ; ignored ...
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 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
Directive MACRO/ENDM • name MACRO [param1[,param2]] • LOCAL loc1,loc2 • ... • ... • ENDM
Multiple-defined labels in Macro Expansion delay Macro label: EndM Solution: delay Macro Local label label: EndM ... delay ... delay ... . label: . . label: .
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
IF statememts [ELSE statements] ENDIF IF expression IFE expression IFDEF name IFNDEF name Directive Conditional
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 $ Example Conditional Assembler
Directive File Control .LIST .NOLIST .LISTMACRO .NOLISTMACRO .LISTINCLUDE .NOLISTINCLUDE MESSAGE INCLUDE
HIGH/LOW OFFSET SHR/SHL Example: data .section 'data' array db 10 dup(?) code .section 'code' mov a,11111111b SHR 1 ;7fH mov a,0ffh AND 0fh ; 0fH mov a,offset array ; mov a,LOW 0abcdh ; cdH mov a,HIGH 0abcd ; abH jmp $ Directive Others
Example: Table Read routine .section page 'code' ; input acc for index, ; output on ‘pattern’ ReadPattern PROC add A,LOWOFFSET 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(?)
76543210 BP Bank (Organization) ROM RAM 0H 0H 40H ... ... 1FFFH FFH
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’
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
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?