Page 1 of 1

How to know first instruction in GAS assembler?

Posted: Sat Sep 01, 2012 7:30 am
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

Re: How to know first instruction in GAS assembler?

Posted: Sat Sep 01, 2012 12:04 pm
by Owen
GAS isn't designed to generate binary files. You must use a linker script in order to guarantee the correct padding

Re: How to know first instruction in GAS assembler?

Posted: Sat Sep 01, 2012 2:10 pm
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?

Re: How to know first instruction in GAS assembler?

Posted: Sat Sep 01, 2012 3:42 pm
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.