2 ; This is a very basic implementation of 8051 instruction set, which treats
\r
3 ; all types of addresses as plain numeric values and therefore is not able to
\r
4 ; detect whether symbol has been used in context it was not intended for.
\r
15 element @R1? : @ + 1
\r
20 if value and not 7FFh = ($+2) and not 7FFh
\r
21 db 01h + value shr 3 and 11100000b,value and 0FFh
\r
23 err "address out of range"
\r
30 if value and not 7FFh = ($+2) and not 7FFh
\r
31 db 11h + value shr 3 and 11100000b,value and 0FFh
\r
33 err "address out of range"
\r
40 db 12h,value shr 8,value and 0FFh
\r
46 db 02h,value shr 8,value and 0FFh
\r
51 offset = -($+2)+addr
\r
52 if offset>=-80h & offset<80h
\r
55 err "relative jump out of range"
\r
62 if value and not 7FFh = ($+2) and not 7FFh
\r
63 db 11h + value shr 3 and 11100000b
\r
72 match =@A? + =DPTR?, addr
\r
76 offset = value-($+2)
\r
77 if offset>=-80h & offset<80h
\r
80 if value and not 7FFh = ($+2) and not 7FFh
\r
81 db 01h + value shr 3 and 11100000b
\r
90 macro CJNE? operand1,operand2,addr
\r
92 offset = -($+3)+addr
\r
93 if offset>=-80h & offset<80h
\r
95 match #data, operand2
\r
102 else match #data,operand2
\r
104 if value eq value element 1
\r
105 if value metadata 1 relativeto @
\r
106 db 0B6h + value metadata 1 - @
\r
107 else if value metadata 1 relativeto R
\r
108 db 0B8h + value metadata 1 - R
\r
110 err "invalid operand"
\r
114 err "invalid operand"
\r
117 err 'invalid operand'
\r
121 err "relative jump out of range"
\r
125 macro DJNZ? operand,addr
\r
128 if value relativeto 0
\r
129 offset = -($+3)+addr
\r
130 if offset>=-80h & offset<80h
\r
131 db 0D5h,value,offset
\r
133 err "relative jump out of range"
\r
135 else if value eq value element 1 & value metadata 1 relativeto R
\r
136 offset = -($+2)+addr
\r
137 if offset>=-80h & offset<80h
\r
138 db 0D8h + value metadata 1 - R,offset
\r
140 err "relative jump out of range"
\r
143 err "invalid operand"
\r
147 macro JBC? operand,addr
\r
149 offset = -($+3)+addr
\r
150 if offset>=-80h & offset<80h
\r
151 db 10h,operand,offset
\r
153 err "relative jump out of range"
\r
157 macro JB? operand,addr
\r
159 offset = -($+3)+addr
\r
160 if offset>=-80h & offset<80h
\r
161 db 20h,operand,offset
\r
163 err "relative jump out of range"
\r
167 macro JNB? operand,addr
\r
169 offset = -($+3)+addr
\r
170 if offset>=-80h & offset<80h
\r
171 db 30h,operand,offset
\r
173 err "relative jump out of range"
\r
179 offset = -($+2)+addr
\r
180 if offset>=-80h & offset<80h
\r
183 err "relative jump out of range"
\r
189 offset = -($+2)+addr
\r
190 if offset>=-80h & offset<80h
\r
193 err "relative jump out of range"
\r
199 offset = -($+2)+addr
\r
200 if offset>=-80h & offset<80h
\r
203 err "relative jump out of range"
\r
209 offset = -($+2)+addr
\r
210 if offset>=-80h & offset<80h
\r
213 err "relative jump out of range"
\r
217 macro ADD? accu,operand
\r
220 match #data, operand
\r
225 if value relativeto 0
\r
227 else if value eq value element 1
\r
228 if value metadata 1 relativeto @
\r
229 db 26h + value metadata 1 - @
\r
230 else if value metadata 1 relativeto R
\r
231 db 28h + value metadata 1 - R
\r
233 err "invalid operand"
\r
236 err "invalid operand"
\r
240 err 'invalid operand'
\r
244 macro ADDC? accu,operand
\r
247 match #data, operand
\r
252 if value relativeto 0
\r
254 else if value eq value element 1
\r
255 if value metadata 1 relativeto @
\r
256 db 36h + value metadata 1 - @
\r
257 else if value metadata 1 relativeto R
\r
258 db 38h + value metadata 1 - R
\r
260 err "invalid operand"
\r
263 err "invalid operand"
\r
267 err 'invalid operand'
\r
271 macro SUBB? accu,operand
\r
274 match #data, operand
\r
279 if value relativeto 0
\r
281 else if value eq value element 1
\r
282 if value metadata 1 relativeto @
\r
283 db 96h + value metadata 1 - @
\r
284 else if value metadata 1 relativeto R
\r
285 db 98h + value metadata 1 - R
\r
287 err "invalid operand"
\r
290 err "invalid operand"
\r
294 err 'invalid operand'
\r
298 macro ANL? dest,src
\r
299 local value,data_value
\r
306 if value relativeto 0
\r
308 else if value eq value element 1
\r
309 if value metadata 1 relativeto @
\r
310 db 56h + value metadata 1 - @
\r
311 else if value metadata 1 relativeto R
\r
312 db 58h + value metadata 1 - R
\r
314 err "invalid operand"
\r
317 err "invalid operand"
\r
320 else match =C?, dest
\r
330 else match #data, src
\r
333 db 53h,value,data_value
\r
335 err 'invalid operand'
\r
340 macro ORL? dest,src
\r
341 local value,data_value
\r
348 if value relativeto 0
\r
350 else if value eq value element 1
\r
351 if value metadata 1 relativeto @
\r
352 db 46h + value metadata 1 - @
\r
353 else if value metadata 1 relativeto R
\r
354 db 48h + value metadata 1 - R
\r
356 err "invalid operand"
\r
359 err "invalid operand"
\r
362 else match =C?, dest
\r
372 else match #data, src
\r
375 db 43h,value,data_value
\r
377 err 'invalid operand'
\r
382 macro XRL? dest,src
\r
383 local value,data_value
\r
390 if value relativeto 0
\r
392 else if value eq value element 1
\r
393 if value metadata 1 relativeto @
\r
394 db 66h + value metadata 1 - @
\r
395 else if value metadata 1 relativeto R
\r
396 db 68h + value metadata 1 - R
\r
398 err "invalid operand"
\r
401 err "invalid operand"
\r
408 else match #data, src
\r
411 db 63h,value,data_value
\r
413 err 'invalid operand'
\r
421 else match =C?, operand
\r
431 else match =C?, operand
\r
438 macro SETB? operand
\r
452 if value relativeto 0
\r
454 else if value eq value element 1
\r
455 if value metadata 1 relativeto @
\r
456 db 16h + value metadata 1 - @
\r
457 else if value metadata 1 relativeto R
\r
458 db 18h + value metadata 1 - R
\r
460 err "invalid operand"
\r
463 err "invalid operand"
\r
472 else match =DPTR?, operand
\r
476 if value relativeto 0
\r
478 else if value eq value element 1
\r
479 if value metadata 1 relativeto @
\r
480 db 06h + value metadata 1 - @
\r
481 else if value metadata 1 relativeto R
\r
482 db 08h + value metadata 1 - R
\r
484 err "invalid operand"
\r
487 err "invalid operand"
\r
492 macro MOV? dest,src
\r
493 local value,data_value
\r
500 if value relativeto 0
\r
502 else if value eq value element 1
\r
503 if value metadata 1 relativeto @
\r
504 db 0E6h + value metadata 1 - @
\r
505 else if value metadata 1 relativeto R
\r
506 db 0E8h + value metadata 1 - R
\r
508 err "invalid operand"
\r
511 err "invalid operand"
\r
514 else match =C?, dest
\r
516 else match =C?, src
\r
518 else match =DPTR?, dest
\r
524 db value shr 8,value and 0FFh
\r
528 if value relativeto 0
\r
531 else match #data, src
\r
533 db 75h,value,data_value
\r
536 if @value2 relativeto 0
\r
537 db 85h,@value2,value
\r
538 else if @value2 eq @value2 element 1
\r
539 if @value2 metadata 1 relativeto @
\r
540 db 86h + @value2 metadata 1 - @,value
\r
541 else if @value2 metadata 1 relativeto R
\r
542 db 88h + @value2 metadata 1 - R,value
\r
545 err "invalid operand"
\r
548 else if value eq value element 1
\r
549 if value metadata 1 relativeto @
\r
551 db 0F6h + value metadata 1 - @
\r
552 else match #data, src
\r
554 db 76h + value metadata 1 - @,data_value
\r
557 db 0A6h + value metadata 1 - @,data_value
\r
559 else if value metadata 1 relativeto R
\r
561 db 0F8h + value metadata 1 - R
\r
562 else match #data, src
\r
564 db 78h + value metadata 1 - R,data_value
\r
567 db 0A8h + value metadata 1 - R,data_value
\r
570 err "invalid operand"
\r
573 err "invalid operand"
\r
578 macro MOVC? operands&
\r
579 match =A?=, =@A? + =DPTR?, operands
\r
581 else match =A?=, =@A? + =PC?, operands
\r
584 err "invalid operand"
\r
588 macro MOVX? dest,src
\r
595 if value eq value element 1 & value metadata 1 relativeto @
\r
596 db 0E2h + value metadata 1 - @
\r
598 err "invalid operand"
\r
601 else match =A?, src
\r
602 match =@DPTR?, dest
\r
606 if value eq value element 1 & value metadata 1 relativeto @
\r
607 db 0F2h + value metadata 1 - @
\r
609 err "invalid operand"
\r
613 err "invalid operand"
\r
617 macro SWAP? operand
\r
621 err 'invalid operand'
\r
629 err 'invalid operand'
\r
637 err 'invalid operand'
\r
645 err 'invalid operand'
\r
653 err 'invalid operand'
\r
661 err 'invalid operand'
\r
666 match =AB?, operand
\r
669 err "invalid operand"
\r
674 match =AB?, operand
\r
677 err "invalid operand"
\r
705 macro XCH? accu,operand
\r
709 if value relativeto 0
\r
711 else if value eq value element 1
\r
712 if value metadata 1 relativeto @
\r
713 db 0C6h + value metadata 1 - @
\r
714 else if value metadata 1 relativeto R
\r
715 db 0C8h + value metadata 1 - R
\r
717 err "invalid operand"
\r
720 err "invalid operand"
\r
723 err 'invalid operand'
\r
727 macro XCHD? accu,src
\r
731 if value eq value element 1 & value metadata 1 relativeto @
\r
732 db 0D6h + value metadata 1 - @
\r
734 err "invalid operand"
\r
737 err "invalid operand"
\r
748 macro DSEG? @:at DSEG?.$
\r
756 err 'invalid argument'
\r
770 err 'invalid argument'
\r
774 macro bitslabel definition
\r
775 match name =at? address, definition
\r
776 label name at address
\r
778 label name.i at address+i
\r
787 bitslabel P0 at 080h
\r
788 bitslabel SP at 081h
\r
789 bitslabel DPL at 082h
\r
790 bitslabel DPH at 083h
\r
791 bitslabel PCON at 087h
\r
792 bitslabel TCON at 088h
\r
793 bitslabel TMOD at 089h
\r
794 bitslabel TL0 at 08Ah
\r
795 bitslabel TL1 at 08Bh
\r
796 bitslabel TH0 at 08Ch
\r
797 bitslabel TH1 at 08Dh
\r
798 bitslabel P1 at 090h
\r
799 bitslabel SCON at 098h
\r
800 bitslabel SBUF at 099h
\r
801 bitslabel P2 at 0A0h
\r
802 bitslabel IE at 0A8h
\r
803 bitslabel P3 at 0B0h
\r
804 bitslabel IP at 0B8h
\r
805 bitslabel PSW at 0D0h
\r
806 bitslabel ACC at 0E0h
\r
807 bitslabel B at 0F0h
\r
856 label RESET at 000h
\r
857 label EXTI0 at 003h
\r
858 label TIMER0 at 00Bh
\r
859 label EXTI1 at 013h
\r
860 label TIMER1 at 01Bh
\r