Add imm_xchg_w and xchg_w commands, change XXXrev to xchg_XXX, tidy up slightly
authorNick Downing <nick@ndcode.org>
Sun, 16 Jun 2019 11:08:35 +0000 (21:08 +1000)
committerNick Downing <nick@ndcode.org>
Sun, 16 Jun 2019 11:08:35 +0000 (21:08 +1000)
sm2.asm

diff --git a/sm2.asm b/sm2.asm
index 7fed975..61bd2db 100644 (file)
--- a/sm2.asm
+++ b/sm2.asm
@@ -11,30 +11,7 @@ page1        =       2
        jp      start
 
 page0_trace:
-       ld      l,c
-       ld      h,b
-       call    print_word
-       ld      a,' 
-       call    print_char
-       ld      hl,0
-       push    af
-       add     hl,sp
-       pop     af
-       call    print_word
-       ld      a,' 
-       call    print_char
-       pop     hl
-       push    hl
-       call    print_word
-       ld      a,0xd
-       call    print_char
-       ld      a,0xa
-       call    print_char
-       ld      a,(bc)
-       inc     bc
-       ld      l,a
-       ld      h,page0
-       jp      (hl)
+       jp      print_trace
 
 page0_esc:
        ld      l,c
@@ -49,8 +26,26 @@ page0_page1:
        inc     h ; page 1
        jp      (hl)
 
+page0_imm_xchg_w:
+       ld      a,(bc)
+       inc     bc
+       ld      l,a
+       ld      a,(bc)
+       inc     bc
+       ld      h,a
+       .db     0x3e ; ld a,
+page0_xchg_w:
+       pop     hl
+       ex      (sp),hl
+       push    hl
+       ld      a,(bc)
+       inc     bc
+       ld      l,a
+       ld      h,page0
+       jp      (hl)
+
 page0_imm_call:
-       ld      a,(bc)  
+       ld      a,(bc)
        inc     bc
        ld      l,a
        ld      a,(bc)
@@ -86,7 +81,7 @@ imm_not_taken:
 page0_imm_jtrue:
        jr      nc,imm_not_taken
 page0_imm_jmp:
-       ld      a,(bc)  
+       ld      a,(bc)
        inc     bc
        ld      l,a
        ld      a,(bc)
@@ -120,7 +115,7 @@ page0_jmp:
 
 page0_imm_stkadj:
 imm_stkadj:
-       ld      a,(bc)  
+       ld      a,(bc)
        inc     bc
        ld      l,a
        ld      a,(bc)
@@ -140,7 +135,7 @@ stkadj:
 
 page0_imm_stkptr:
 imm_stkptr:
-       ld      a,(bc)  
+       ld      a,(bc)
        inc     bc
        ld      l,a
        ld      a,(bc)
@@ -160,7 +155,7 @@ stkptr:
 
 page0_imm_stkld_w:
 imm_stkld_w:
-       ld      a,(bc)  
+       ld      a,(bc)
        inc     bc
        ld      l,a
        ld      a,(bc)
@@ -180,10 +175,10 @@ stkld_w:
        ld      h,page1
        jp      (hl)
 
-page0_imm_stkstrev_w:
+page0_imm_xchg_stkst_w:
        pop     de
-imm_stkstrev_w:
-       ld      a,(bc)  
+imm_xchg_stkst_w:
+       ld      a,(bc)
        inc     bc
        ld      l,a
        ld      a,(bc)
@@ -294,8 +289,8 @@ page1_imm_stkld_w:
 page1_stkld_w:
        ex      de,hl
        jr      stkld_w
-page1_imm_stkstrev_w:
-       jr      imm_stkstrev_w
+page1_imm_xchg_stkst_w:
+       jr      imm_xchg_stkst_w
 page1_stkst_w:
        jr      stkst_w
 page1_imm_w:
@@ -427,7 +422,7 @@ page1_add_w:
        ld      h,page1
        jp      (hl)
 
-page1_imm_subrev_w: ; reversed, use with argument 0 for neg, -1 for cpl
+page1_imm_xchg_sub_w: ; reversed, use with argument 0 for neg, -1 for cpl
        ld      a,(bc)
        ld      l,a
        inc     bc
@@ -807,7 +802,7 @@ divnn:      ; negative dividend, negative divisor
 ; needed to make the result 100 + -ff..ff or 1..1ff, so that the decrements
 ; cannot borrow into the upcoming dividend bits also held in a, and there must
 ; be another shift between the scf/rla and increment/decrement so that the scf
-; is implicitly in the 100s place, making the code awkward though it's correct 
+; is implicitly in the 100s place, making the code awkward though it's correct
 
 ; now optimized to only inc/dec a when doing zero-crossing, fix above analysis
 
@@ -1049,8 +1044,31 @@ divn18:  ; done, below
 
 ; debugging
 
-digits:
-       .ascii  '0123456789abcdef'
+print_trace:
+       ld      l,c
+       ld      h,b
+       call    print_word
+       ld      a,' 
+       call    print_char
+       ld      hl,0
+       push    af
+       add     hl,sp
+       pop     af
+       call    print_word
+       ld      a,' 
+       call    print_char
+       pop     hl
+       push    hl
+       call    print_word
+       ld      a,0xd
+       call    print_char
+       ld      a,0xa
+       call    print_char
+       ld      a,(bc)
+       inc     bc
+       ld      l,a
+       ld      h,page0
+       jp      (hl)
 
 print_word:
        push    af
@@ -1097,6 +1115,9 @@ print_char:
        pop     bc
        ret
 
+digits:
+       .ascii  '0123456789abcdef'
+
 ; sm code
 
 start:
@@ -1132,7 +1153,7 @@ sm_main:
        .dw     0
        .db     <page1_imm_div_sw
        .dw     10000
-       .db     <page1_imm_stkstrev_w
+       .db     <page1_imm_xchg_stkst_w
        .dw     2
        .db     <page0_page1
        .db     page1_imm_add_w
@@ -1148,7 +1169,7 @@ sm_main:
        .dw     0
        .db     <page1_imm_div_sw
        .dw     1000
-       .db     <page1_imm_stkstrev_w
+       .db     <page1_imm_xchg_stkst_w
        .dw     2
        .db     <page0_page1
        .db     page1_imm_add_w
@@ -1164,7 +1185,7 @@ sm_main:
        .dw     0
        .db     <page1_imm_div_sw
        .dw     100
-       .db     <page1_imm_stkstrev_w
+       .db     <page1_imm_xchg_stkst_w
        .dw     2
        .db     <page0_page1
        .db     page1_imm_add_w
@@ -1180,7 +1201,7 @@ sm_main:
        .dw     0
        .db     <page1_imm_div_sw
        .dw     10
-       .db     <page1_imm_stkstrev_w
+       .db     <page1_imm_xchg_stkst_w
        .dw     2
        .db     <page0_page1
        .db     page1_imm_add_w
@@ -1238,7 +1259,7 @@ sm_factorial:
        .dw     1
        .db     <page0_imm_jfalse
        .dw     1$
-       
+
        ; no, set up for *result =
        .db     <page0_imm_stkld_w
        .dw     2
@@ -1272,7 +1293,7 @@ sm_factorial:
        ; set *result = sm_factorial(argument - 1) * argument
        .db     <page1_st_w
 
-       ; return 
+       ; return
  .db <page0_trace
        .db     <page0_jmp