Question

In: Computer Science

Assembly Question: I am trying to annotate this code and am struggling to understand what it...

Assembly Question: I am trying to annotate this code and am struggling to understand what it is doing. Can someone please add comments?

.data
.star: .string "*"
.line: .string "\n"
.input: .string "%d"

.count: .space 8

.text
.global main

printstars:
push %rsi
push %rdi

_printstars:
push %rdi
mov $.star, %rdi
xor %rax, %rax
call printf
pop %rdi

dec %rdi
cmp $0, %rdi
jg _printstars

mov $.line, %rdi
xor %rax, %rax
call printf

pop %rdi
pop %rsi

ret

printstarpyramid:

mov %rdi, %rsi
mov $1, %rdi

_printstarpyramid:
call printstars

inc %rdi
cmp %rsi, %rdi
jle _printstarpyramid
ret

main:

mov $.input, %rdi
mov $.count, %rsi
xor %rax, %rax
call scanf

mov (.count), %rdi

call printstarpyramid

Solutions

Expert Solution

//declare variable

.data
.star: .string "*"

//Read input
.line: .string "\n"
.input: .string "%d"

//Count space

.count: .space 8

.text

//Declare global variable
.global main

// Push values into variable s

printstars:
push %rsi
push %rdi

_printstars:
push %rdi

// Move values
mov $.star, %rdi

// Do xor operation
xor %rax, %rax

//Print value
call printf
pop %rdi

dec %rdi

// Compare values
cmp $0, %rdi
jg _printstars

// Move values from one to other

mov $.line, %rdi

// Xor operation
xor %rax, %rax

//Print value
call printf

// Get values

pop %rdi
pop %rsi

ret

printstarpyramid:

//Move values

mov %rdi, %rsi
mov $1, %rdi

_printstarpyramid:
call printstars

inc %rdi
cmp %rsi, %rdi
jle _printstarpyramid
ret

main:

mov $.input, %rdi
mov $.count, %rsi
xor %rax, %rax
call scanf

mov (.count), %rdi

call printstarpyramid

Instruction Working

MOV -- copies the data item referred to by its second operand

PUSH-- places its operand onto the top of the hardware supported stack in memory

POP -- removes the 4-byte data element from the top of the hardware-supported stack into the specified operand (i.e. register or memory location)

INC -- increments the contents of its operand by one

CMP -- Compare the values of the two specified operands

Syntax
cmp <reg>,<reg>
cmp <reg>,<mem>
cmp <mem>,<reg>
cmp <reg>,<con>

JLE - one of the conditional jump instruction

Sytax - jle <label> (jump when less than or equal to)


Related Solutions

Hello, I am struggling to understand some of my accounting homework. Question 01 ) Tulsa Company...
Hello, I am struggling to understand some of my accounting homework. Question 01 ) Tulsa Company is considering investing in new bottling equipment and has two options: Option A has a lower initial cost but would require a significant expenditure to rebuild the machine after four years; Option B has higher maintenance costs, but also has a higher salvage value at the end of its useful life. Tulsa’s cost of capital is 11 percent. The following estimates of the cash...
Please give an explanation or what the rational of the code is about, I am trying...
Please give an explanation or what the rational of the code is about, I am trying to figure it out what it means so to better understand it. Discuss the Code Provision on Square and Rectangular HSS and Box- Shaped Members, Rounds HSS, Tees and Double Angles Loaded in the Plane of Symmetry, and Single Angles.
I am trying to plot a difficult function in MATLAB, however I need to understand the...
I am trying to plot a difficult function in MATLAB, however I need to understand the basics first. I am trying to plot n=0 for x=0:0.01:2pi n=n+1 y(n)=sin(x) end I beleive what this says, is that I want to plot sin(x) over a full period hence from o to 2pi, and I beleive the 0.01 is the incremenation along the x-axis. I am not sure what my n is doing Could smeone please graph this for me with the MATLAB...
Currently I am working with Pull up and pull down registers and trying to understand what...
Currently I am working with Pull up and pull down registers and trying to understand what does it mean? But could not able to understand. I searched in Wikipedia but still confused.
I am still struggling to understand the logic of th Ti-inspire CX calculator for inverse binomial...
I am still struggling to understand the logic of th Ti-inspire CX calculator for inverse binomial N Sample Problem Monique is practicing goal shots for netball. She knows from experience that her chance of making any one shot is70%. She plans to practice until she scores 50 goals. How many shots must she attempt to ensure that the probability of making at least 50 goals is more than 0.99? What do I need to input in the Ti nspire under:...
Hi, I am struggling to understand this worksheet my professor gave us for practice. Could someone...
Hi, I am struggling to understand this worksheet my professor gave us for practice. Could someone make any sense of this? The scenario: Sodium is found largely in the extracellular compartment with concentrations between 130-145 mM with intracellular sodium concentrations between 3.5-5mM. This chemical difference gives sodium a large concentration gradient, which when permitted (by opening of a channel or through facilitated transport) will move down its concentration gradient to enter the cell. Sodium also has a favorable electrical gradient;...
This is my code for python. I am trying to do the fourth command in the...
This is my code for python. I am trying to do the fourth command in the menu which is to add an employee to directory with a new phone number. but I keep getting error saying , "TypeError: unsupported operand type(s) for +: 'dict' and 'dict". Below is my code. What am I doing wrong? from Lab_6.Employee import * def file_to_directory(File): myDirectory={}       with open(File,'r') as f: data=f.read().split('\n')    x=(len(data)) myDirectory = {} for line in range(0,199):      ...
I am trying to write a code in C for a circuit board reads in a...
I am trying to write a code in C for a circuit board reads in a temperature from a sensor on the circuit board and reads it onto a 7-segment LED display. How exactly would you code a floating 2 or 3 digit reading onto the LED display? I am stuck on this part.
I am not quite sure what this question is asking, nor do I understand how to...
I am not quite sure what this question is asking, nor do I understand how to apply the lower-of-cost-or-NRV. The controller of Alt Company is applying the lower-of-cost-or-net realizable value basis of valuing its ending inventory. The following information is available: Cost Net Realizable Value Lawnmowers: Self-propelled $14,800 $17,000 Push type 19,000 18,000 Total 33,800 35,000 Snowblowers: Manual 29,800 31,000 Self-start 19,000 21,000 Total 48,800 52,000 Total inventory $82,600 $87,000 Compute the value of the ending inventory by applying the...
Hello I am needing an example of how to write an assembly (MIPS) code that with...
Hello I am needing an example of how to write an assembly (MIPS) code that with will ask the user for two numbers then for addition or multiplication by typing in + or * into the command prompt. For example if I type in the number 2 and 5 then + The code should add the sum between the two numbers like 2 + 3 + 4 + 5 = 14. If multiplication is implemented then it will do the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT