Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data...
-
Upload
albert-burke -
Category
Documents
-
view
245 -
download
8
Transcript of Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data...
![Page 1: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/1.jpg)
Introduction to Holtek ASM Programming
![Page 2: Introduction to Holtek ASM Programming. Section-based Programming Relocatable segment of code/data Logical division of program.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/2.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/3.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/4.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/5.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/6.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/7.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/8.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/9.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/10.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/11.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/12.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/13.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/14.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/15.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/16.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/17.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/18.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/19.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/20.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/21.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/22.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/23.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/24.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/25.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/26.jpg)
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.](https://reader034.fdocuments.us/reader034/viewer/2022051018/56649e925503460f94b97d84/html5/thumbnails/27.jpg)
Map file
• Result of section relocation
– Absolute starting address
– Length
• Public symbol
– sorted by name/offset
• What if source too big?