Skip to content

Code reduction suggestion #38

Description

@tazgm

You can remove two 'jmp PutChar' (4 bytes) :

--- sectorlisp.S
+++ sectorlisp.S
@@ -67,7 +67,9 @@
        jbe     2f
        stosb
        xchg    %ax,%si
-2:     call    GetChar                         # exchanges dx and ax
+2:     xor     %ax,%ax                         # GetChar→al:dl
+       int     $0x16                           # get keystroke
+       call    PutChar                         # exchanges dx and ax
        cmp     $' ',%al
        jbe     1b
        cmp     $')',%al
@@ -90,8 +92,14 @@
        jz      4f                              # jump if nil
        mov     $249,%al                        # bullet (A∙B)
        call    .PutObject
-4:     mov     $')',%al
-       jmp     PutChar
+4:     mov     $'\r'^'\n'^')',%al
+PutLf: xor     $'\r'^'\n',%al
+PutChar:mov    $0x0e,%ah                       # prints CP-437
+       int     $0x10                           # vidya service
+       cmp     $'\r',%al                       # don't clobber
+       je      PutLf                           # look xchg ret
+       xchg    %dx,%ax
+       ret

 .PutObject:                                    # .PutObject(c:al,x:si)
 .PrintString:                                  # nul-terminated in si
@@ -132,17 +140,6 @@
 9:     pop     %cx
        ret

-GetChar:xor    %ax,%ax                         # GetChar→al:dl
-       int     $0x16                           # get keystroke
-PutChar:mov    $0x0e,%ah                       # prints CP-437
-       int     $0x10                           # vidya service
-       cmp     $'\r',%al                       # don't clobber
-       jne     .RetDx                          # look xchg ret
-       mov     $'\n',%al
-       jmp     PutChar
-.RetDx:        xchg    %dx,%ax
-       ret
-
 ////////////////////////////////////////////////////////////////////////////////

 Evlis: test    %di,%di                         # Evlis(m:di,a:dx):ax

And inline Cadr (2 bytes):

--- sectorlisp.S
+++ sectorlisp.S
@@ -233,8 +230,6 @@
        mov     (%bx,%si),%si
        scasw
        jne     1b
-       .byte   0xF6                            # testb §i8,i16(%bp,%di) jmp Car
-Cadr:  mov     (%bx,%di),%di                   # contents of decrement register
        .byte   0x3C                            # cmp §scasw,%al (nop next byte)
 Cdr:   scasw                                   # increments our data index by 2
 Car:   mov     (%di),%ax                       # contents of address register!!
@@ -250,7 +245,8 @@
        jz      1b
        push    (%di)                           # push Car(c)
 .EvCadr:pop    %di
-       call    Cadr                            # ax = Cadar(c)
+       mov     (%bx,%di),%di
+       mov     (%di),%ax                       # ax = Cadar(c)
 #      jmp     Eval

 Eval:  test    %ax,%ax                         # Eval(e:ax,a:dx):ax

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions