0

I am reading Linux 0.11's source code these days.And when I tried to modify it and print some hardware's properties on the screen, there are errors from as86:

make BootImage
as86 -0 -a -o boot/setup.o boot/setup.s
00056 0050           A1         0000                mov ax, [bx]
***** register used as identifier................................^

00056 0050           A1         0000                mov ax, [bx]
**** register used as identifier................................^

00001 errors
00000 warnings
make: *** [Makefile:97:boot/setup]

And here is my code:

INITSEG=0x9000
!print those information
mov cx,#5
mov bx,#msgs
mov ax,#INITSEG
mov ds,ax

print_words:
mov si,[bx]
call print_msg
add bx,2
loop print_words

print_msg:
push ax
push bx
push cx
push dx

mov ah,#0x03
xor bh,bh
int 0x10

mov cx,[si]
add si,2
mov bx,#0x0007
mov ax,#0x1301
int 0x10

pop dx
pop cx
pop bx
pop ax

ret

msgs:
.word cursor,memory,cyls,heads,sectors
cursor:
.word 0x0012
.byte 13,10
.ascii "Cursor Position:"
memory:
.word 0x0009
.byte 13,10
.ascii "Memory:"
cyls:
.word 0x0007
.byte 13,10
.ascii "Cyls:"
heads:
.word 0x0008
.byte 13,10
.ascii "Heads:"
sectors:
.word 0x000A
.byte 13,10
.ascii "Sectors:"

I have checked them online but I can't find the reason why I can't use bx register to access memory, and I have found that in as86, we can access memory by the way of [bx] or [bx + k * si]. So I'm a little confused. Thank you for your help.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
TherLF
  • 13
  • 5
  • 1
    Did you check what syntax as86 uses? Presumably it's different from NASM-style Intel syntax for addressing modes. (Also note that 16-bit addressing modes don't support a scale factor, so `[bx]` or `[bx + si]` are legal, but `[bx + 2*si]` wouldn't be.) – Peter Cordes May 01 '21 at 05:05
  • 4
    According to [the documentation](https://linux.die.net/man/1/as86), the `-a` switch "swaps the interpretation of round brackets and square brackets..." – Raymond Chen May 01 '21 at 05:15
  • Thank you for your help! I change the square brackets to round brackets, and I made it! Thank you! – TherLF May 01 '21 at 06:36

0 Answers0