📄 extra.asm
字号:
; User installable disassembler and single-step run for paulmon2; Please email comments, suggestions, bugs to paul@pjrc.com; This code is in the public domain. It is distributed in; the hope that it will be useful, but without any warranty;; without even the implied warranty of merchantability or fitness; for a particular purpose.; For more information, please see; http://www.pjrc.com/tech/8051/pm2_docs/index.html.equ locat, 0x1000 ;location for these commands (usually 1000).equ paulmon2, 0x0000 ;location where paulmon2 is at (usually 0000).equ phex1, 0x2E+paulmon2.equ cout, 0x30+paulmon2 ;send acc to uart.equ phex, 0x34+paulmon2 ;print acc in hex.equ phex16, 0x36+paulmon2 ;print dptr in hex.equ pstr, 0x38+paulmon2 ;print string @dptr.equ ghex, 0x3A+paulmon2 ;get two-digit hex (acc).equ ghex16, 0x3C+paulmon2 ;get four-digit hex (dptr).equ upper, 0x40+paulmon2 ;convert acc to uppercase.equ newline, 0x48+paulmon2.equ pcstr, 0x45+paulmon2.equ pint, 0x50+paulmon2.equ smart_wr, 0x56+paulmon2.equ cin_filter, 0x62+paulmon2.equ asc2hex, 0x65+paulmon2.equ list_key, 'L' ;list (disassemble).equ step_key, 'S' ;single step run.equ vtedit_key, 'E' ;memory editor;for testing in ram;.equ list_key, 'K' ;list (disassemble);.equ step_key, 'W' ;single step run;.equ vtedit_key, 'E' ;memory editor;location of two bytes used by single-step in internal ram which we;hope the user's program won't write over while it's running. These;two bytes hold the address of the previous instruction, so we can;show the last executed instruction with the current value of the;registers, which is much more intuitive than displaying the next;instruction by grabbing the program counter from the stack as was;done in PAULMON1's single step..equ lastpc, 0x7C ;don't forget to update the docs below;DIS;---------------------------------------------------------;; ;; list command ;; ;;---------------------------------------------------------;.org locat.db 0xA5,0xE5,0xE0,0xA5 ;signiture.db 254,list_key,0,0 ;id (254=user installed command).db 0,0,0,0 ;prompt code vector.dB 0,0,0,0 ;reserved.db 0,0,0,0 ;reserved.db 0,0,0,0 ;reserved.db 0,0,0,0 ;user defined.db 255,255,255,255 ;length and checksum (255=unused).db "List",0newline_h:ljmp newline.org locat+64 ;executable code begins here; disassembler register usage; r0 = temporary storage; r1 = temporart storage; r2 = first instruction byte; r3 = second instruction byte; r4 = third instruction byte; r5 = line count; r6 = program counter (lsb); r7 = program counter (msb)list: acall newline_h mov r5, #20 clr psw.1 ;use ordinary long formatlist2: acall disasm djnz r5, list2 ajmp newline_hdisasm:;print out the memory location and fetch the next three bytes mov a, r7 mov dph, a acall phex_h mov a, r6 mov dpl, a acall phex_h clr a movc a, @a+dptr mov r2, a inc dptr clr a movc a, @a+dptr mov r3, a inc dptr clr a movc a, @a+dptr mov r4, a mov a, r2 anl a, #00001000b jnz lookup2;fetch constants for instructions not using R0-R7lookup1: mov a, r2 rr a anl a, #01111000b ;grab upper 4 bits mov r0, a ;keep in r0 for a moment mov a, r2 anl a, #00000111b ;get lower 3 bits orl a, r0 ;combine in upper 4 mov dptr, #opot1 ;opot=operand offset table movc a, @a+dptr sjmp unpack;fetch constants for R0-R7 instructionslookup2: mov a, r2 swap a anl a, #00001111b mov dptr, #opot2 movc a, @a+dptr;now we'll unpack the operand code (# bytes and addr mode)unpack: anl a, #00000011b mov r0, a;increment the r7/r6 pointer add a, r6 mov r6, a mov a, r7 addc a, #0 mov r7, a;now print the bytes and spaces (r0 has # of bytes to print)pbytes: mov a, #':' acall cout_h acall space_h jb psw.1, pmnu ;skip bytes if running single-step mov a, r2 acall phex_h acall space_h cjne r0, #1, pbytes2 mov r1, #11 sjmp pbytes4pbytes2:mov a, r3 acall phex_h acall space_h cjne r0, #2, pbytes3 mov r1, #8 sjmp pbytes4pbytes3:mov a, r4 acall phex_h mov r1, #6pbytes4:acall space_h djnz r1, pbytes4;prints the mnunonic name and spacespmnu: mov a, r2 anl a, #00001000b jnz pmnu_lookup2pmnu_lookup1: mov dptr, #mnot1 ;mnot=mnunonic offset table mov a, r2 rr a anl a, #01111000b ;grab upper 4 bits mov r0, a ;keep in r0 for a moment mov a, r2 anl a, #00000111b ;get lower 3 bits orl a, r0 ;combine in upper 4 movc a, @a+dptr mov r1, a sjmp pmnu0pmnu_lookup2: mov dptr, #mnot2 ;16 byte table for r0-r7 instructions mov a, r2 swap a anl a, #00001111b movc a, @a+dptr mov r1, apmnu0: mov dptr, #mnu_tbl mov r0, #8 clr cpmnu1: mov a, #' ' jc pmnu2 mov a, r1 movc a, @a+dptr inc r1 mov c, acc.7 anl a, #0x7Fpmnu2: acall cout_h djnz r0, pmnu1;print the operands mov a, #dasm2 & 255 ;(low) push acc mov a, #dasm2 >> 8 ;(high) push accam_lookup0: mov a, r2 anl a, #00001000b jnz am_lookup2;fetch constants for instructions not using R0-R7am_lookup1: mov a, r2 rr a anl a, #01111000b ;grab upper 4 bits mov r0, a ;keep in r0 for a moment mov a, r2 anl a, #00000111b ;get lower 3 bits orl a, r0 ;combine in upper 4 mov dptr, #opot1 ;opot=operand offset table movc a, @a+dptr sjmp am_unpack;fetch constants for R0-R7 instructionsam_lookup2: mov a, r2 swap a anl a, #00001111b mov dptr, #opot2 movc a, @a+dptram_unpack: anl a, #11111100b rr a rr a dec a mov dptr, #oprt ;oprt=operand routine table rl a add a, dpl mov dpl, a clr a addc a, dph mov dph, a clr a jmp @a+dptrdasm2: ajmp newline_hoprt: ajmp opcd1 ;addr11 ajmp opcd2 ;A,Rn ajmp opcd3 ;A,direct ajmp opcd4 ;A,@Ri ajmp opcd5 ;A,#data ajmp opcd6 ;direct,A ajmp opcd7 ;direct,#data ajmp opcd8 ;C,bit ajmp opcd9 ;C,/bit ajmp opcd10 ;A,direct,rel ajmp opcd11 ;A,#data,rel ajmp opcd12 ;Rn,#data,rel ajmp opcd13 ;@Ri,#data,rel ajmp pa ;A ajmp prc ;C ajmp pbit ;bit ajmp pdirect ;direct ajmp p_reg_i ;@Ri ajmp opcd19 ;AB ajmp opcd20 ;Rn,rel ajmp opcd21 ;direct,rel ajmp p_reg_n ;Rn ajmp pdptr ;DPTR ajmp opcd24 ;bit,rel ajmp prel ;rel ajmp opcd26 ;@A+DPTR ajmp opcd27 ;addr16 ajmp opcd28 ;Rn,A ajmp opcd29 ;Rn,direct ajmp opcd30 ;Rn,#data ajmp opcd31 ;direct,Rn ajmp opcd32 ;direct,direct ajmp opcd33 ;direct,@Ri ajmp opcd34 ;@Ri,A ajmp opcd35 ;@Ri,direct ajmp opcd36 ;@Ri,#data ajmp opcd37 ;bit,C ajmp opcd38 ;DPTR,#data16 ajmp opcd39 ;A,@A+DPTR ajmp opcd40 ;A,@A+PC ajmp opcd41 ;A,@DPTR ajmp opcd42 ;@DPTR,A ret ; <nothing>opcd4: ;A,@Ri done acall pacp_reg_i:mov a,#'@' acall cout_h mov a,#'R' acall cout_h mov a, r2 anl a,#00000001b ajmp phex1_hopcd3: ;A,direct done acall pacpdirect: mov a, r3 jb acc.7,pdir1pdir0: mov a, r3 ajmp phex_hpdir1: mov dptr,#sfrmnupdir2: clr a movc a,@a+dptr inc dptr jz pdir0 mov r0,a clr c subb a, r3 jnz pdir3pstr_h: ljmp pstrpdir3: clr a movc a,@a+dptr inc dptr jnb acc.7,pdir3 sjmp pdir2 opcd9: ;C,/bit done acall prc acall pcomma mov a, #'/' acall cout_hpbit: mov a, r3 anl a,#01111000b rl a swap a mov r0,a mov a, r3 anl a,#10000000b jz pbit1 mov dptr,#bitptr ;it's a Special Function Reg. mov a,r0 movc a,@a+dptr mov dptr,#bitmnu addc a,dpl mov dpl,a jnc pbit0 inc dphpbit0: acall pstr_h sjmp pbit2pbit1: mov a,r0 ;it's between 20h and 2Fh add a,#20h acall phex_hpbit2: mov a,#'.' acall cout_h mov a, r3 anl a,#00000111b ajmp phex1_hopcd10: ;A,direct,rel done acall pac acall pdirectopcd10a:acall pcomma mov a, r4 mov r3, aprel: mov a, r3 add a, r6 mov dpl, a mov a, r3 jb acc.7, prel2 clr a sjmp prel3prel2: clr a cpl aprel3: addc a, r7 mov dph, a ljmp phex16pat: ;prints the '@' symbol mov a,#'@' ajmp cout_hpac: ;print "A," acall papcomma: ;prints a comma mov a,#',' acall cout_hpspace: mov a, #' ' ajmp cout_hplb: ;prints the '#' symbol mov a,#'#' ajmp cout_hopcd6: ;direct,A done acall pdirect acall pcommapa: ;prints 'A' mov a,#'A' ajmp cout_hopcd37: ;bit,C done acall pbit acall pcommaprc: ;prints 'C' mov a,#'C' ajmp cout_hopcd26: ;@A+DPTR done acall pat acall pa mov a,#'+' acall cout_hpdptr: ;prints DPTR mov a, #'D' acall cout_h mov a, #'P' acall cout_h mov a, #'T' acall cout_h mov a, #'R'cout_h: ljmp coutopcd1: mov a, r7 ;addr11 done anl a, #11111000b mov r0, a mov a, r2 swap a rr a anl a, #00000111b orl a, r0 acall phex_h mov a, r3 ajmp phex_hopcd2: ;A,Rn done acall pacp_reg_n:mov a,#'R' acall cout_h mov a, r2 anl a,#00000111bphex1_h: ljmp phex1opcd5: ;A,#data done acall papdata: acall pcomma acall plb mov a, r3phex_h: ljmp phexopcd7: ;direct,#data done acall pdirect mov a, r4 mov r3, a ajmp pdataopcd8: ;C,bit done acall prc acall pcomma ajmp pbitopcd11: ;A,#data,rel done acall paopcd11a:acall pcomma acall plb mov a, r3 acall phex_h ajmp opcd10aopcd12: ;Rn,#data,rel done acall p_reg_n ajmp opcd11aopcd13: ;@Ri,#data,rel done acall p_reg_i ajmp opcd11aopcd19: ;AB done acall pa mov a, #'B' ajmp cout_hopcd20: ;Rn,rel done acall p_reg_n acall pcomma ajmp prelopcd21: ;direct,rel done acall pdirect ajmp opcd10aopcd24: ;bit,rel done
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -