Click to See Complete Forum and Search --> : Input integer


Bluefox815
September 7th, 2008, 04:01 PM
I'm sorry for the incorrect thread title. My browser isn't working properly and that was meant for something else. By the time I caught the mistake it was too late. Title should have been "String indexing"

How do I index a string with a register? If I have a string I can index it with a literal but not a register. Like this:

(Compiler: TASM 5.0)

.model small
.stack
.data
message db 'Hello, world!$' ; The string

.code

main proc

mov ax, seg message
mov ds, ax

mov ah, message[3] ; Works

mov cx, 3
mov ah, message[cx] ; Does not work

mov ch, 3
mov ah, message[ch] ; Does not work either

main endp
end main


Is there a way I can index a string with something other than a number literal? The error generated by the compiler is: Illegal indexing mode

S_M_A
September 7th, 2008, 05:18 PM
It's a long time since I programmed in assembly so I migth be wrong but...

I guess that without .386 statement the assembler will only accept code valid for 8086/88 and I don't think indexing with cx was allowed. If I remember correctly the only registers that were used for this were es:bx, ds:si and ds/es:di. Try using bx instead of cx.

olivthill
September 7th, 2008, 06:08 PM
The offset of message can be placed in SI, DI, BX, or BP, e.g.
mov si, offset message
mov ah, [si + 3]Available addressing modes are:
DS:[SI + disp8] (in 16-bit mode)
DS:[SI + disp16] (in 16-bit mode)
DS:[ESI + disp8] (in 32-bit mode)
DS:[ESI + disp32] (in 32-bit mode)
DS:[DI + disp8] (in 16-bit mode)
DS:[DI + disp16] (in 16-bit mode)
DS:[EDI + disp8] (in 32-bit mode)
DS:[EDI + disp32] (in 32-bit mode)

DS:[BX + disp8] (in 16-bit mode)
DS:[BX + disp16] (in 16-bit mode)
DS:[BX + SI] (in 16-bit mode)
DS:[BX + SI + disp8] (in 16-bit mode)
DS:[BX + SI + disp16] (in 16-bit mode)
DS:[BX + DI] (in 16-bit mode)
DS:[BX + DI + disp8] (in 16-bit mode)
DS:[BX + DI + disp16] (in 16-bit mode)

DS:[BP + disp8] (in 16-bit mode)
DS:[BP + disp16] (in 16-bit mode)
DS:[BP + SI] (in 16-bit mode)
DS:[BP + SI + disp8] (in 16-bit mode)
DS:[BP + SI + disp16] (in 16-bit mode)
DS:[BP + DI] (in 16-bit mode)
DS:[BP + DI + disp8] (in 16-bit mode)
DS:[BP + DI + disp16] (in 16-bit mode)

DS:[EAX + disp8] (in 32-bit mode)
DS:[EAX + disp32] (in 32-bit mode)
DS:[EBX + disp8] (in 32-bit mode)
DS:[EBX + disp32] (in 32-bit mode)
DS:[ECX + disp8] (in 32-bit mode)
DS:[ECX + disp32] (in 32-bit mode)
DS:[EDX + disp8] (in 32-bit mode)
DS:[EDX + disp32] (in 32-bit mode)
DS:[EBP + disp8] (in 32-bit mode)
DS:[EBP + disp32] (in 32-bit mode)

Bluefox815
September 7th, 2008, 10:28 PM
Thank you for the list of valid instructions. However, I don't know what "disp" means. I would assume it refers to a number literal with the specified number of bits, but I want to be sure.

olivthill
September 8th, 2008, 03:40 AM
Yes, it is.