I wrote a x86-64 code in Assembly Language. The output is 17.
.text.LC0: .string "%d\n"printint: pushq %rbp movq %rsp, %rbp subq $16, %rsp movl %edi, -4(%rbp) movl -4(%rbp), %eax movl %eax, %esi leaq .LC0(%rip), %rdi movl $0, %eax call printf@PLT nop leave ret .globl main .type main, @functionmain: pushq %rbp movq %rsp, %rbp movq $2, %r8 movq $3, %r9 movq $5, %r10 imulq %r9, %r10 addq %r8, %r10 movq $8, %r8 movq $3, %r9 movq %r8,%rax cqo idivq %r9 movq %rax,%r8 subq %r10, %r8 movq %r10, %rdi call printint movl $0, %eax popq %rbp ret
When i Compile this wth GCC, I got this errors.
out.s: Assembler messages:out.s:5: Error: bad register name `%rbp'out.s:6: Error: bad register name `%rsp'out.s:7: Error: bad register name `%rsp'out.s:8: Error: bad register name `%rbp)'out.s:9: Error: bad register name `%rbp)'out.s:11: Error: bad register name `%rip)'out.s:19: Warning: .type pseudo-op used outside of .def/.endef: ignored.out.s:19: Error: junk at end of line, first unrecognized character is `m'out.s:21: Error: bad register name `%rbp'out.s:22: Error: bad register name `%rsp'out.s:23: Error: bad register name `%r8'out.s:24: Error: bad register name `%r9'out.s:25: Error: bad register name `%r10'out.s:26: Error: bad register name `%r9'out.s:27: Error: bad register name `%r8'out.s:28: Error: bad register name `%r8'out.s:29: Error: bad register name `%r9'out.s:30: Error: bad register name `%r8'out.s:31: Error: `cqo' is only supported in 64-bit modeout.s:32: Error: bad register name `%r9'out.s:33: Error: bad register name `%rax'out.s:34: Error: bad register name `%r10'out.s:35: Error: bad register name `%r10'out.s:38: Error: bad register name `%rbp'
Similarly when I did this in NASM, I got the following errors.
out.s:1: warning: label alone on a line without a colon might be in error [-w+orphan-labels]out.s:3: error: parser: instruction expectedout.s:5: error: parser: instruction expectedout.s:6: error: expression syntax errorout.s:7: error: parser: instruction expectedout.s:8: error: parser: instruction expectedout.s:9: error: parser: instruction expectedout.s:10: error: parser: instruction expectedout.s:11: error: parser: instruction expectedout.s:12: error: parser: instruction expectedout.s:18: error: parser: instruction expectedout.s:19: error: parser: instruction expectedout.s:21: error: label `pushq' inconsistently redefinedout.s:5: note: label `pushq' originally defined hereout.s:21: error: parser: instruction expectedout.s:22: error: expression syntax errorout.s:23: error: expression syntax errorout.s:24: error: expression syntax errorout.s:25: error: expression syntax errorout.s:26: error: parser: instruction expectedout.s:27: error: parser: instruction expectedout.s:28: error: expression syntax errorout.s:29: error: expression syntax errorout.s:30: error: expression syntax errorout.s:32: error: parser: instruction expectedout.s:33: error: expression syntax errorout.s:34: error: label `subq' inconsistently redefinedout.s:7: note: label `subq' originally defined hereout.s:34: error: parser: instruction expectedout.s:35: error: expression syntax errorout.s:37: error: label `movl' inconsistently redefinedout.s:8: note: label `movl' originally defined hereout.s:37: error: parser: instruction expectedout.s:38: error: parser: instruction expected
But when i went to https://www.onlinegdb.com/online_gcc_assembler and compiled it, I got the correct answer (17).
I'm still learning assembly language. I searched for an answer, but could not found one. Can you explain the reason for this ?
Details about my Laptop
AMD RYZEN 5 Processor ( x64 Based )
64bit Windows 10