0

Basically, I want to use a value that keeps changing in the effective address, so I can print 3 characters of the figure in each line (I'm trying to print different figures at the same time in the same line).

%include "io.mac"

.DATA
   figure db ' t ','tt ',' t ',' t ','ttt'
   variable db 0

.CODE
   .STARTUP

loop:
   ;... variable increases until max 5
   
   PutCh [figure+(3*variable)]
   PutCh [figure+(3*variable)+1]
   PutCh [figure+(3*variable)+2]
   nwln

   ;... jmp to loop

or another representation of the problem (by only printing one char)

   xor bx,bx

loop:
   mov al, [figure+bx]
   PutCh al
   inc bx

I've also tried using %assign but when I change the value by doing another %assign, it stays with the original value. I've tried using the bx register but it produces the relocation truncated to fit r_386_16 against .bss' error when I try to link it. Any ideas?

J.S.
  • 13
  • 3
  • 1
    Always keep in mind the difference between *assemble time* and *run time* expressions. `[figure+(3*variable)+1]` uses the addresses of `figure` and `variable`. In NASM `x` means the address of `x`. You need to compute `3*variable` with instructions (e.g. `lea`). You also need to use a 32 address mode (e.g. `[figure+ebx]`) or properly deal with 64-bit addressing. Though, I would expect a `R_386_16` relocation. – Margaret Bloom Apr 24 '21 at 08:04
  • 1
    Use registers, that's what they're for. x86 doesn't have memory-indirect addressing modes where you can use the contents of memory as the index (or any other part of an address). And when you use a register, use 32-bit registers in 32-bit mode. – Peter Cordes Apr 24 '21 at 08:09

0 Answers0