Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,60 @@
;; MS-DOS Nim; assembles with nasm.
bits 16
cpu 8086
getch: equ 1
putch: equ 2
puts: equ 9 ; INT 21h calls
maxtokens: equ 12 ; Amount of tokens there are
section .text
org 100h
mov dx,nim ; Print sign-on
call outs
mov ch,maxtokens ; CH = amount of tokens we have
loop: mov dx,tokens ; Tokens: |||...
call outs
mov ah,putch ; Print a | for each token
mov dl,'|'
mov dh,ch
puttoks: int 21h
dec dh
jnz puttoks
mov dx,prompt ; Ask the user how many to take
call outs
ask: mov ah,getch ; Read keypress
int 21h
sub al,'1' ; Make number (minus one)
jc bad ; Carry, it was <1 (bad)
inc al ; Add 1 (because we subtracted '1')
cmp al,3
ja bad ; If it was >3, it is bad
cmp al,ch
ja bad ; If it was > amount left, it is bad
sub ch,al ; Remove your tokens from pile
mov cl,4 ; I take 4-N, which is 3-N-1
sub cl,al
sub ch,cl ; Remove my tokens from pile
mov dx,response ; Tell the user how many I took.
call outs
mov dl,'0'
add dl,cl
mov ah,putch
int 21h
cmp ch,0 ; Are there any tokens left?
jne loop ; If not, prompt again
mov dx,lose ; But otherwise, you've lost
; Fall through into print string routine and then stop.
;; Print string in DX. (This saves a byte each CALL)
outs: mov ah,puts
int 21h
ret
;; Input is bad; beep, erase, ask again
bad: mov dx,wronginp
call outs
jmp ask
section .data
nim: db 'Nim$'
prompt: db 13,10,'How many will you take (1-3)? $'
response: db 13,10,'I take $'
tokens: db 13,10,13,10,'Tokens: $'
lose: db 13,10,'You lose!$'
wronginp: db 8,7,32,8,'$'