I'm working on some assembly code (x86 AT&T) that checks to see if a triangle is valid, but I can't get it to work. Here's what I've got so far.
.data
.a: .int 7
.b: .int 10
.c: .int 5
.valid .string "True %d\n"
.invalid .string "False %d\n"
.global main
checkTriangle:
#a + b > c
mov .a, %rdi
mov .b, %rsi
mov .c, %rdx
add %rdi, %rsi
cmpq %rsi, %rdx
jg .L4
ret
.L4:
#a + c > b
mov .a, %rdi
mov .b, %rsi
mov .c, %rdx
add %rdi, %rdx
cmpq %rdx, %rsi
jg .L5
ret
.L5:
#b + c > a
mov .a, %rdi
mov .b, %rsi
mov .c, %rdx
add %rsi, %rdx
cmpq %rdx, %rdi
ret
main:
call checkTriangle
Basically, the code needs to print true if the triangle is valid, and false if the triangle is invalid. I've already got the conditions worked out but I don't know how to get it to print.
.data
.a: .int 7
.b: .int 10
.c: .int 5
.valid .string "True %d\n"
.invalid .string "False %d\n"
.global main
checkTriangle:
#a + b > c
mov .a, %rdi
mov .b, %rsi
mov .c, %rdx
add %rdi, %rsi
cmpq %rsi, %rdx
jg .L4
ret
.L4:
#a + c > b
mov .a, %rdi
mov .b, %rsi
mov .c, %rdx
add %rdi, %rdx
cmpq %rdx, %rsi
jg .L5
ret
.L5:
#b + c > a
mov .a, %rdi
mov .b, %rsi
mov .c, %rdx
add %rsi, %rdx
cmpq %rdx, %rdi
ret
main:
call checkTriangle
It is not the problem with the code maybe the data
once check the data because i can see no wrong in code
Get Answers For Free
Most questions answered within 1 hours.