pgubook-readers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pgubook-readers] Addressing modes - chapter 6


From: David Rappo
Subject: [Pgubook-readers] Addressing modes - chapter 6
Date: Mon, 29 Dec 2008 18:15:52 +1100

Hi,

I've got a few questions about addressing modes.

I'm working through the exercises in Chapter 6. One of my programs has
the following line of code:

# .equ K_RECORD_AGE_INDEX, 320
# .lcomm record_buffer, K_RECORD_SIZE

movl $21, $K_RECORD_AGE_INDEX + record_buffer

When I try to assemble the program, I get the following error:

main.s:181: Error: suffix or operands invalid for `mov'

I don't understand why I am receiving this error. I am trying to move
an immediate-mode value (21) to the memory address $K_RECORD_AGE_INDEX
+ record_buffer.

I placed a $ in front of K_RECORD_AGE_INDEX because I want to add the
value of K_RECORD_AGE_INDEX (not its address) to wherever
record_buffer starts in memory.

Can somebody explain what I am doing wrong?

The following code assembles fine, and the principles seem to be the same.

movl $K_RECORD_ADDRESS_INDEX + record_buffer, %ecx

Finally, the add-year program in Chapter 6 uses the following code to
increment the year part of a record:

# .equ K_RECORD_AGE_INDEX, 320
# .lcomm record_buffer, K_RECORD_SIZE
incl record_buffer + K_RECORD_AGE_INDEX

There is no $ sign in front of K_RECORD_AGE_INDEX so the code would
seem to be adding the address of K_RECORD_AGE_INDEX to the value of
the first byte in record_buffer, which doesn't accomplish anything.

record_buffer is also in front of K_RECORD_AGE_INDEX instead of after it.

Can anybody explain the difference between:

(1) incl record_buffer + K_RECORD_AGE_INDEX
(2) movl $K_RECORD_ADDRESS_INDEX + record_buffer, %ecx

Yes - they are different operations (incl versus movl), but I am
really confused as to why the $ sign is omitted in (1)

Thanks,

David




reply via email to

[Prev in Thread] Current Thread [Next in Thread]