Question Details

No question body available.

Tags

assembly x86 x86-16

Answers (1)

Accepted Answer Available
Accepted Answer
March 20, 2026 Score: 5 Rep: 41,637 Quality: Expert Completeness: 80%

I was very pleased to see you explain the program in great detail, but at the same time your source code is totally lacking (tail)comments! Definitely something to work on...

Your grd subroutine is a bit special!

You subtract 48 from every inputted character code whether it represents a digit or not, and you abandon returning from it once three inputs were received. While the latter works fine, you should probably not be doing that while learning the language.
Subtracting 48 on every input is also what gave that awkward test for program termination (add al, 48 cmp al, 81). Incidentally, you can write this as cmp al, 'Q' which is a lot clearer.

I would not use a subroutine like you wrote, but keep it all in a straightforward loop:

org 100h
mov di, 5000   ; Teletype uses BH (BX) for its display page

cun: xor ah, ah ; BIOS.ReadKeystroke int 16h ; -> AX cmp al, 'Q' ; Test before anything else (no echo needed) je fin mov bx, 0007h ; Teletype uses BH (BX) for its display page mov ah, 0Eh ; Do the echo BEFORE you convert anything! int 10h sub al, '0' ; Convert AND check for decimal digit cmp al, 10 jb Gotit add al, '0' ; Restore original ASCII Gotit: stosb ; AL={[0,9],"+","-"} cmp di, 5003 jb cun

mov bx, 5000 mov cl, [bx] ; First operand mov dl, [bx+2] ; Second operand cmp byte [bx+1], "+" je sum cmp byte [bx+1], "-" je res jmp cun ; Redo
  • In case the operator was anything except "+" or "-", you should not fall through in sum but rather redo from start (or quit).
  • Beware: I reduced the storage space to one byte per datum.
  • Observe that you are not restricted to just [bx]. In NASM you can also add an offset like in [bx+1].