Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

linux - Meaning of assembly instructions

I am working my way through http://www.amazon.com/Assembly-Language-Step-Step-Programming/dp/0470497025.

Currently, I'm trying to move some of the code around so that I can compile with GAS, instead of NASM (the book's default compiler), and I'm having trouble understanding what some of it means.

This is my source code of confusion

EatMsg: db *Eat at Joe's!* , 10

EatLen: equ $-EatMst

(it's in .section .data)

how would I rewrite it to work with GAS?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Generally, you'd have to study the documentation of nasm to see what the construct is doing, then read the gas manual on how to achieve the equivalent thing.

In this case, db is defining some data bytes, and the equ defines an alias for the length, using $ for the current address. The code for gas is:

EatMsg:
    .ascii "*Eat at Joe's*"
    .byte 10
.equ EatLen, . - EatMsg

You could also incorporate the 10 (which is the ascii code of line feed) as into the string.

The simplest solution would be to simply install nasm, of course.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...