Question

I'm working on some assembly code (x86 AT&T) that checks to see if a triangle is...

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.

Homework Answers

Answer #1

.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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Convert this C++ program exactly as you see it into x86 assembly language: // Use the...
Convert this C++ program exactly as you see it into x86 assembly language: // Use the Irvine library for the print function #include <iostream> // The string that needs to be printed char word[] = "Golf\0"; // Pointer to a specific character in the string char * character = word; //NOTE: This main() function is not portable outside of Visual Studio void main() { // Set up a LOOP - See the while loop's conditional expression below int ecx =...
In assembly masm use the code below! Write a program that reverse a string using indirect...
In assembly masm use the code below! Write a program that reverse a string using indirect addressing (may not use the stack - push/pop). The string will be given by the user and be up to 64 characters long INCLUDE Irvine32.inc INCLUDE macros.inc MAX = 64 .data source BYTE MAX DUP('#'),0 destination BYTE LENGTHOF source DUP('*'),0 actual_length DWORD ? ask BYTE "Enter a String: ",0 .code main proc ; ask user for input mov edx, OFFSET ask call WriteString ;...
C++ 1. Modify the code from your HW2 as follows: Your triangle functions will now return...
C++ 1. Modify the code from your HW2 as follows: Your triangle functions will now return a string object. This string will contain the identification of the triangle as one of the following (with a potential prefix of the word “Right ”): Not a triangle Scalene triangle Isosceles triangle Equilateral triangle 2. All output to cout will be moved from the triangle functions to the main function. 3. The triangle functions are still responsible for rearranging the values such that...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
Hello i am working on a project for my programming course and i am a little...
Hello i am working on a project for my programming course and i am a little lost. The assignment is as follows: Part A Do all of problem 3.13 (Employee Class), including the main, as written. Part B Now, suppose a new company policy says that instead of the monthly salary we will now store the yearly salary. We will need to make this change inside Employee and support the new usage, without breaking existing code (such as the old...
In Chapter 9, you created a Contestant class for the Greenville Idol competition. The class includes...
In Chapter 9, you created a Contestant class for the Greenville Idol competition. The class includes a contestant’s name, talent code, and talent description. The competition has become so popular that separate contests with differing entry fees have been established for children, teenagers, and adults. Modify the Contestant class to contain a field that holds the entry fee for each category, and add get and set accessors. Extend the Contestant class to create three subclasses: ChildContestant, TeenContestant, and AdultContestant. Child...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing associated with the assignment it is failing one part of testing.   Below is the test that fails: Failed test 4: differences in output arguments: -c input data: a b c -c expected stdout: b observed stdout: a b expected stderr: observed stderr: ./test: invalid option -- 'c' Unsure where I have gone wrong. MUST BE WRITTEN IN C++ Task Level 1: Basic operation Complete...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
Hi there, I've been asked to write a program in C which can read values from...
Hi there, I've been asked to write a program in C which can read values from a file then sort them, and then write to a binary file. I'm getting stuck when I write my binary file as the output is just spitting out garbage values and not the values that are being read in. When I print my input file reader everything is perfect but after sorting and then writing, the output is completely wrong. I have checked that...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT