0

You all were kind enough to help me recently with understanding this language a bit better. I'm working on AT&T syntax x86_64 assembly language through an Apress book. The author gives this code, which, amazingly, I understand fairly well. But obviously not as well as I'd like. It won't link. I get undefined reference errors for the six "name" labels defined at the top (gkcname, et al.). I've checked the code to make sure it matches the author's many times over. It does.

The code is meant to be linked with another file, but I consolidated things and tried placing the entry point right here in this file just to be sure that wasn't related to the problem. Same error. I'm a complete newbie so I'm sure I'm missing something obvious. Help would be appreciated. Thank you again. All the best.

.section .data gkcname: .ascii "Gilbert Keith Chester\0" jbname: .ascii "Jonathan Bartlett\0" cslname: .ascii "Clist Silver Lewis\0" taname: .ascii "Tommy Aquinas\0" inname: .ascii "Isaac Newn\0" gmname: .ascii "Gregory Mend\0" .globl people, numpeople numpeople: .quad (endpeople-people)/PERSON_RECORD_SIZE people: .quad $gkcname, 200, 10, 2, 74, 20 .quad $jbname, 280, 12, 2, 72, 44 .quad $cslname, 150, 8, 1, 68, 30 .quad $taname, 250, 14, 3, 75, 24 .quad $inname, 250, 10, 2, 70, 11 .quad $gmname, 180, 11, 5, 69, 65 endpeople: .globl NAME_PTR_OFFSET, WEIGHT_OFFSET, SHOE_OFFSET .globl HAIR_OFFSET, HEIGHT_OFFSET, AGE_OFFSET .equ NAME_PTR_OFFSET, 0 .equ WEIGHT_OFFSET, 8 .equ SHOE_OFFSET, 16 .equ HAIR_OFFSET, 24 .equ HEIGHT_OFFSET, 32 .equ AGE_OFFSET, 40 .globl PERSON_RECORD_SIZE .equ PERSON_RECORD_SIZE, 48 

1 Answer 1

4
 .quad $gkcname, 200, 10, 2, 74, 20 

The $ prefix isn't used when specifying a label or other value to be assembled as data using .quad, .byte, etc. It's only used for immediate operands to actual instructions.

I expect that if you look closely at the error message, the undefined reference wasn't to gckname but actually to $gckname. That's what I got in my tests. That is, in this context, the assembler understood $gckname to be a reference to a symbol with an actual dollar sign in its name, which of course has not been defined.

(In future, please paste the actual error messages into your question, instead of trying to summarize them in your own words!)

Simply remove the $ signs to make it:

 .quad gkcname, 200, 10, 2, 74, 20 

and so on. Then it assembles and links successfully for me.

It looks as though the book is Learn to Program with Assembly by Jonathan Bartlett. I checked and this is in fact the code that appears on page 96-97, so you didn't miscopy it. So that's an error on the part of the author, and is concerning as it suggests that they can't have actually tested their own code. I'm not aware that any version of the GNU assembler has ever accepted $ as a prefix there.

Sign up to request clarification or add additional context in comments.

4 Comments

That's disappointing for that book. His earlier book "Programming from the Ground Up." for i386 looked pretty good from the parts I skimmed, and also uses AT&T syntax. (It's free, in both senses: GFDL licensed and available to download.) But of course it's easy to miss stuff like this.
I'm going to check that out when I'm done with this one. Thanks.
Yup, spot on. It's not his first mistake in this text. It's been a good book overall and I'm learning the material as well as could be expected (granted, with some help from you fine folks). But yeah, there's been two other places where I noticed mistakes. Apress usually does well with these books. This one just feels like it wasn't given the time and attention it needed. Thank you for taking the time to respond. I hadn't seen the $ used in statements like these anywhere else, but we just started covering strings and so I thought it was something unique to that data type. Much appreciated.
Worked like a charm without the $'s. Thank you very much.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.