Error in Calculating Section Size with .set Directive in x86_64 Assembly

I am learning to write a bootloader. In the process of converting hexadecimal values to strings in x86 64 assembly on a linux system with an Intel Core i7 processor , when I try to assemble this code using as, I encounter the following error:
$ as -o print_bios.o print_bios.S
print_bios.S: Assembler messages:
print_bios.S: Error: invalid operands (.data and *UND* sections) for `-' when setting `hex_size'
$ as -o print_bios.o print_bios.S
print_bios.S: Assembler messages:
print_bios.S: Error: invalid operands (.data and *UND* sections) for `-' when setting `hex_size'
I'm not sure why this error is occurring. From my source code the .set directive is intended to calculate the size of the .hex_str section. Could you please help me understand the issue and provide a solution?
attachment 0
Solution:
Thanks , been able to fix this :salute:
Jump to solution
3 Replies
Enthernet Code
Enthernet Code3mo ago
@Marvee Amasi The error you encountered when assembling your code (Error: invalid operands (.data and *UND* sections) for '-' when setting 'hex_size') suggests that the .set directive is incorrectly used, involving symbols from incompatible sections. To correctly calculate the size of a data section ( string), ensure that the labels used for size calculation are within the same section. - Place a start label before your data (e.g., hex_str_start) and an end label after it (e.g., hex_str_end). - Use these labels to calculate the size: .set hex_size, hex_str_end - hex_str_start. This approach ensures that both labels are defined within the same section ( .data), allowing for valid arithmetic operations. This should resolve the assembler error related to operand incompatibility.
Solution
Marvee Amasi
Marvee Amasi3mo ago
Thanks , been able to fix this :salute:
Want results from more Discord servers?
Add your server