Search code examples
assemblygnu-assembler

Fail assembly if file is too large in gnu as


I am trying to assemble a file whose binary must fit in a specific size. I’ve been trying to see if there was a way for the assembler to fail if it’s too big so that I know. I was thinking something like:

.if . > 0x200
.error “binary too large”
.endif

But this doesn’t work as the if express is not absolute. I tried doing it with a label as well but it also doesn’t work. Is there a way to do this with directives or within as?


Solution

  • Apparently if you set the current address to something less than it should be, the assembling will fail. So concluding the file with

    . = 0x200
    

    Causes as to throw an error if the file was larger then that.

    Edit: As pointed out by @fuz, this will pad the file to that size, I don’t have an answer if this is an issue for you.