Seki
Seki

Reputation: 11465

mov al, byte[si + bx] becomes mov al, [bx+si+1]

While trying to provide a full working (debugged) example for this question, I cannot understand the assembled code. I am a bit rusty with the good old DOS + TASM combination.

This is my asm code (print.asm):

.MODEL SMALL
.STACK 64
.DATA
    string DB 'Something'
    len equ $-string

.CODE

Entry:
    mov ax, @data   ;make DS point to our DATA segment
    mov ds, ax

    xor bx, bx    
    mov si, offset string

Char:
    mov al, byte[si + bx]
    mov ah, 2
    mov dl, al
    int 21h

    inc bx
    cmp bx, len
    jnz Char

Fin:
    mov ax, 4c00h
    int 21h

END Entry

I assemble with

tasm print.asm
tlink print.obj

resulting in the 16bit executable print.exe.

When testing, i am surprised to see that the program outputs

omething

When I look at the assembled object, I can see:

_TEXT:0000 start:
_TEXT:0000                 mov     ax, seg DGROUP
_TEXT:0003                 mov     ds, ax
_TEXT:0005                 xor     bx, bx
_TEXT:0007                 mov     si, offset unk_10030
_TEXT:000A
_TEXT:000A loc_1001A:                              ; CODE XREF: _TEXT:0017j
_TEXT:000A                 mov     al, [bx+si+1]   ; <== I do not understand the '+1'
_TEXT:000D                 mov     ah, 2
_TEXT:000F                 mov     dl, al
_TEXT:0011                 int     21h             ; DOS - DISPLAY OUTPUT
_TEXT:0011                                         ; DL = character to send to standard output
_TEXT:0013                 inc     bx
_TEXT:0014                 cmp     bx, 9
_TEXT:0017                 jnz     short loc_1001A
_TEXT:0019                 mov     ax, 4C00h
_TEXT:001C                 int     21h             ; DOS - 2+ - QUIT WITH EXIT CODE (EXIT)
_TEXT:001C                                         ; AL = exit code

and I am puzzled with the generated mov al, [bx+si+1] from my mov al, byte[si + bx] that points 1 byte from the begining of the string.

Upvotes: 1

Views: 1199

Answers (1)

Michael
Michael

Reputation: 58467

byte[si + bx] is NASM syntax. In TASM syntax that's equivalent to [si + bx + byte], which is equal to [si + bx + 1].

In the TASM manual in the section "Expressions" you've got a table named "Standard symbol values" where you can see that the symbol "BYTE" corresponds to the value 1.

What you want is byte ptr [si + bx]. Or you can simply use [si + bx] in this case since there's no ambiguity (because the size of al is known to the assembler).

Upvotes: 7

Related Questions