Answer the question
In order to leave comments, you need to log in
How to enter and display a number in assembler(AT&T, GAS syntax)?
Welcome all.
I'm learning to develop on Assembler
During the training, a task arose - writing a calculator.
I'm writing under Linux(Ubuntu), so I have to learn the GAS(AT&T) syntax.
There was a problem with the output, namely when compiling this code:
.data
number:
.long 0x00000595
str:
.space 4, 0
i:
.byte 0
str_len =.-str
.text
.global _start
_start:
0:
addb $str, i
movb $0x30, (%eax)
incb %al
movb %al, (i)
jmp logic
1:
addb $str, i
movb $0x31, (%eax)
incb %al
movb %al, (i)
jmp logic
2:
addb $str, i
movb $0x32, (%eax)
incb %al
movb %al, (i)
jmp logic
3:
addb $str, i
movb $0x33, (%eax)
incb %al
movb %al, (i)
jmp logic
4:
addb $str, i
movb $0x34, (%eax)
incb %al
movb %al, (i)
jmp logic
5:
addb $str, i
movb $0x35, (%eax)
incb %al
movb %al, (i)
jmp logic
6:
addb $str, i
movb $0x36, (%eax)
incb %al
movb %al, (i)
jmp logic
7:
addb $str, i
movb $0x37, (%eax)
incb %al
movb %al, (i)
jmp logic
8:
addb $str, i
movb $0x38, (%eax)
incb %al
movb %al, (i)
jmp logic
9:
addb $str, i
movb $0x39, (%eax)
incb %al
movb %al, (i)
jmp logic
logic:
movl $number, %eax
cdq
movl $10, %ebx
idivl %ebx
cmpl $0, %edx
je 0
cmpl $1, %edx
je 1
cmpl $2, %edx
je 2
cmpl $3, %edx
je 3
cmpl $4, %edx
je 4
cmpl $5, %edx
je 5
cmpl $6, %edx
je 6
cmpl $7, %edx
je 7
cmpl $8, %edx
je 8
cmpl $9, %edx
je 9
movl $4, %eax
movl $1, %ebx
movl $str, %ecx
movl $str_len, %edx
int $0x80
movl $1, %eax
xor %ebx, %ebx
int $0x80
$ as --64 test_print.s -o test_print.o
$ ld -melf_x86_64 -s test_print.o -o test_print
test_print.o: In function `_start':
(.text+0x7): relocation truncated to fit: R_X86_64_8 against `.data'
(.text+0x21): relocation truncated to fit: R_X86_64_8 against `.data'
(.text+0x3b): relocation truncated to fit: R_X86_64_8 against `.data'
(.text+0x55): relocation truncated to fit: R_X86_64_8 against `.data'
(.text+0x6f): relocation truncated to fit: R_X86_64_8 against `.data'
(.text+0x86): relocation truncated to fit: R_X86_64_8 against `.data'
(.text+0x9d): relocation truncated to fit: R_X86_64_8 against `.data'
(.text+0xb4): relocation truncated to fit: R_X86_64_8 against `.data'
(.text+0xcb): relocation truncated to fit: R_X86_64_8 against `.data'
(.text+0xe2): relocation truncated to fit: R_X86_64_8 against `.data'
Answer the question
In order to leave comments, you need to log in
I write under Linux (Ubuntu), therefore I have to master the syntax of GAS (AT & T)
addb $str, i relocation truncated to fit: R_X86_64_8 against `.data'
int $0x80
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question