0

I'm new in assembly. I'm trying to get the forming triangle in assembly. When I compile it, I get a "32-bit absolute addressing is not supported in 64-bit mode" error. Can you explain what I miss? And is the way I did correct

#include <stdio.h>

int main()
{
    int a, b, c;

    scanf("%d %d %d", &a, &b, &c);
    if(c < a + b && b < a + c && a < b + c)
        printf("yes");
    else
        printf("no");
}

This is my code.

.data
.yes: .string "Yes"
.no: .string "No"
.global main


tri:
    push %rsi
    push %rdx

    add %rdi, %rsi # a + b
    cmp %rdx, %rsi # a + b > c
    jle no
    pop %rsi
    add %rsi, %rdx # c + a 
    cmp %rdi, %rdx # c + a > b
    jle no
    pop %rdx
    add %rdx, %rdi # b + c
    cmp %rsi, %rdi # b + c > a
    jle no 

    mov $.yes, %rdi
    mov %rax, %rsi
    xor %rax, %rax
    call printf
    ret
no:
    mov $.no, %rdi
    mov %rax, %rsi
    xor %rax, %rax
    call printf
    ret

main:
    mov $2, %rsi
    mov $2, %rdi
    mov $3, %rdx
    call tri




 
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Soomin Im
  • 11
  • 1
  • 2
  • 2
    What operating system are you programming for? To fix this issue, replace `mov $.yes, %rdi` with `lea .yes(%rip), %rdi` and `mov $.no, %rdi` with `lea .no(%rip), %rdi`. – fuz Oct 22 '20 at 17:31
  • I'm using a macOS. After I replaced them, it says segmentation fault (core dumped). Fundamentally, is the way I do the triangular formation condition in assembly correct? – Soomin Im Oct 22 '20 at 18:08
  • 1
    One thing that immediately jumps to my eye is that you push `rsi` and `rdx` in `tri` but then fail to pop them off the stack before returning to `main`. This will cause a crash. I recommend you to terminate your strings with `\n` so they get flushed out immediately. This'll tell you if the program crashes before or after the `printf` calls. – fuz Oct 22 '20 at 19:09

0 Answers0