NASM TO GAS: counterpart of resw in GAS

邮差的信 提交于 2019-12-24 16:58:27

问题


I am tasked to convert my assembly program which uses NASM to GAS. Unfortunately there are lots of mismatched statements. I have converted some of them but I am still having trouble on how to convert this statement

min resw 1

回答1:


You could try:

.lcomm min, 2

or

.comm min, 2

to put aside space for two bytes (one word) in the bss section. The point of the bss section is that the loader will allocate space and set the content to zero on load, but it won't take up space in your file on disk.

.lcomm is if you only need to refer to min from inside the file where you use .lcomm. comm is if you need to refer to min from other files (so the linker will make it available to other files).

If you prefer to use the data section, which will put the zeros in your file and take up space on disk, then this, placed in the data section, should work:

min:
    .fill 2



回答2:


Reserving one word (with an initializer of 0) is pretty easy:

min:    .word    0

For x86, .word is 16-bit. For other sizes: .byte, .long, .quad.


If you wanted to reserve a large chunk, say 50 words, use the .fill or .space directives:

buff1:  .fill    50, 1, 0     # count, size, value
buff2:  .space   50, 0        # count (bytes), value (defaults to 0)

For initializers with a repeating pattern wider than 1 byte, .dcb.size takes a value and length:

int_array:  .dcb.l  50, 12345       # 32-bit integer 12345 repeated 50 times


来源:https://stackoverflow.com/questions/27266676/nasm-to-gas-counterpart-of-resw-in-gas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!