How to know first instruction in GAS assembler?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Locked
xiangzhc
Posts: 2
Joined: Sat Sep 01, 2012 7:21 am

How to know first instruction in GAS assembler?

Post by xiangzhc »

What I want to achieve is to calculate the length of the code segment.
In Masm Compiler, we can get it just through

Code: Select all

($-$$)
But how to get it through GAS assembler?
Here's my code, but when compiling, it returns
" Error: bad or irreducible absolute expression"

Code: Select all

.text
.global _start
#.code16

_start:
  jmp over
os_size:
  .word 0
  .word 0

over:
  movw $100, %ax

forever:
  jmp forever

foo:

.rept . - _start
  .byte 0
.endr
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: How to know first instruction in GAS assembler?

Post by Owen »

GAS isn't designed to generate binary files. You must use a linker script in order to guarantee the correct padding
xiangzhc
Posts: 2
Joined: Sat Sep 01, 2012 7:21 am

Re: How to know first instruction in GAS assembler?

Post by xiangzhc »

Owen wrote:GAS isn't designed to generate binary files. You must use a linker script in order to guarantee the correct padding
Thanks for your reply. Could you please add more code here? So that I can search for that.

By the way, when linking, we can specify segment location like:

Code: Select all

ld -Ttext=0x0 -o bootblock bootblock.c
The abovementioned code script is taken from our assignment. What confused me is the fact that bootblock/bootloader would be loaded into 0x07c00 by BIOS, but why we specify code segment to 0x0?

Does that imply the cs register is assigned to 0x07c0 automatically?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: How to know first instruction in GAS assembler?

Post by Combuster »

...okay...
Image
Linking source files, asking about homework, you just broke two forum rules like really hard.


Go back to asking your teacher. You paid him after all.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Locked