R16K1S60

  • 12Me21
    1st Jun 2017 Member 2 Permalink

    I made a simple number guessing game:

     

    It now supports numbers from 0 to 65534!

     

    ;SETUP
    reset:
       ;ax: current guess
    MOV bx,0 ;minimum
       ;cx: carry flag / input port
    MOV dx,0xFFFF ;maximum+1
    ;#
    MOV ex,0 ;# of guesses
       ;sp: unused

    loop:
    ;CALCULATE AVERAGE
    MOV ax,bx ;set ax to minimum
    ADD ax,dx ;add maximum, set carry flag if the sum is >65535
    @noflags MOV cx,0 ;reset cx
    ADC cx,0 ;put carry flag in cx
    SHRD ax,cx,1 ;divide by 2 and set high bit if there was a carry
    ;I wish there was a way to shift in the carry flag directly...

    ;OUTPUT/INPUT
    SEND 0,ax ;display guess
    ADD ex,1 ;increase # of guesses
    WAIT cx ;wait for input
    CMP cx,2 ;compare input to 2
    JA toohigh ;if higher (port 3)
    JB toolow ;if lower (port 1)

    ;CORRECT
    SEND 0,ex ;display # of guesses
    HLT
    JMP reset

    ;TOO HIGH
    toohigh:
    MOV dx,ax ;set maximum to ax
    JMP loop

    ;TOO LOW
    toolow:
    MOV bx,ax ;set minimum to ax
    JMP loop

    Edited 4 times by 12Me21. Last: 3rd Jun 2017
  • IS2511
    4th Jun 2017 Member 0 Permalink

    Best computer in TPT.

    Edited once by IS2511. Last: 4th Jun 2017
  • 12Me21
    5th Jun 2017 Member 0 Permalink

    IS2511:

    Best computer in TPT.

     "not for long"

  • 12Me21
    10th Jun 2017 Member 0 Permalink

    I discovered a bug in the assembler.

    If you use @org, the success message doesn't show the correct number of cells.

    For example

    HLT
    HLT
    HLT
    @org 0
    NOP
    says "4 instructions, 1 cells"

  • CALVIN1390
    12th Oct 2018 Member 0 Permalink