Code reduction suggestion
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 76
- PR merge metrics
- No merged PRs in 30d
Description
You can remove two 'jmp PutChar' (4 bytes) :
```diff
--- 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):
```diff
--- 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
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with sectorlisp.S and inspect GetChar, PutChar, Cadr, and .EvCadr, including their calling and register conventions. Review the proposed inlining and removals, then verify that the boot-sector code retains its input, output, and Cadr behavior while achieving the stated byte reductions.
Written by the indexing model from the issue text.
Assessment
- Domain
- operating-systems
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100