Adam Sh
Adam Sh

Reputation: 8577

Assembler - EQU calculate what?

In the next code:

section .data
    sa db ’abxdefghxl’,0
    la  EQU $ - sa
    sb db ’abcdexghil’,0
section .text

As I saw in my program, when I do mov ecx, la - then I got the number 11 in ECX. I didn't understand why - the number of abxdefghxl is not 10. We also count the 0?

Upvotes: 0

Views: 765

Answers (2)

Ville Krumlinde
Ville Krumlinde

Reputation: 7131

$ represents the current position. And since the current position is after the complete declaration of "sa", the expression $-sa is 11. Remember that in assembly there is no thing like a "string" data type, "sa" is just a collection of bytes.

Upvotes: 1

Pavan Manjunath
Pavan Manjunath

Reputation: 28525

Assume sa to start at 0x400. You have defined 10 ( abxdefghxl ) plus 1 ( 0 at the end ) And hence la wwould start at 0x40B. $ represents the current instruction/directive address. Hence $-sa = 0xB or 11

Upvotes: 2

Related Questions