0

Consider the following

JMP start

leftbr    DB '('
rightbr   DB ')'
key       DB ''

start:
  MOV AH, 08
  INT 21h         ; Read keypress
  MOV [key], AL   ; Store the key pressed in variable 'key'

output:
  MOV DL, leftbr  ; Move the value from 'leftbr' to DL
  MOV AH, 02      
  INT 21h         ; Should output (
  MOV DL, [key]   ; Put the value from 'key' in the DL register
  INT 21h         ; Output 'key'
  MOV DL, rightbr
  INT 21h         ; Output )

exit:
  MOV AH, 4Ch
  MOV AL, 00
  INT 21h         ; Terminate the program

The output I get from this in DosBox is:

Image showing stx and etx characters

According to this site (https://www.ascii-codes.com/) the smiley face and heart are the STX and ETX characters, instead of the brackets as expected.

If I alter the start: block as follows I get the correct output:

start:
  MOV BH, "("
  MOV BL, ")"
  MOV [leftbr], BH
  MOV [rightbr], BL
  MOV AH, 08
  INT 21h         ; Read keypress
  MOV [key], AL   ; Store the key pressed in variable 'key'

Can anyone explain why this would be? I should be able to declare a variable with a initial value.

lewis
  • 846
  • 9
  • 15
  • 1
    Is that your whole source, with no `org` directive? But anyway, `MOV DL, leftbr` puts the address in the register, not the value. It's a `db` stored in memory, not an `equ` assemble-time constant. If you want a memory operand, you need `[leftbr]` like you're doing for the stores in the 2nd version. – Peter Cordes Oct 05 '18 at 20:55
  • You're quite right @PeterCordes, I needed the square brackets but that wasn't the problem (I had removed them to test a theory). Thank you though for pointing me in the direction of ORG. I'm just starting to learn and I think the tutorial I'm following assumed a DOS assembler that assumed the ORG. I added an ORG directive (and the square brackets) and all was good. – lewis Oct 05 '18 at 21:03
  • I found a near-duplicate for `org 0x100`. I'm surprised it was hard to find, but searching on `nasm org 100h` found boatloads of code with some other problem that correctly started with `org 100h`. – Peter Cordes Oct 05 '18 at 21:10

0 Answers0