Assignment 1: Printing integers Right now, the only printing we can do is of fixed strings,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Assignment 1: Printing integers Right now, the only printing we can do is of fixed strings, by using the write syscall. We'll extend this by writing our own code to print 64-bit unsigned integer values. This essentially involves converting a binary value to decimal, using the same procedure we used to convert to binary/hexadecimal: divide repeatedly by 10 and look at the remainders. Converting binary to decimal As with converting decimal to binary, we divide repeatedly (by 10 this time) and use the remainders for the digits. E.g., to convert 101101b to decimal: Binary 101101b 5 100b Ob Remainder Decimal 4 BUFLEN: buffer: section .data _5 45 45 We stop when we get to O. Digits are written in reverse, from the right end of the string. In order to perform the conversion, we will need to pre-allocate a string buffer big enough to hold all the digits of the biggest unsigned 64-bit integer, 18446744073709551615, 20 characters: Home equ times BUFLEN db 20 0 ; Buffer of 20 '\0's (We could also use the .bss section, which is specifically used for uninitialized space, since we don't really need to fill the buffer with Os.) Your code should assume that the value to be converted is stored in register rdi, and the file number to write to in register rsi; it should construct the character representation in the buffer and then call the write syscall to print it to the file number in rsi. Use the following template for your program: section .data BUFLEN: buffer: newline: db section .text global start _start: equ times BUFLEN db mov rsi, 1 mov rdi, 10 call print int mov rsi, 1 mov rdi, 186562354 call print-int mov rsi, 1 mov rdi, 0xdeadbeef12345678 call print int ; End program mov mov syscall print-int: ret rax, 60 rdi, 0 ; Your printing code here 20 0 10 ; Buffer of 20 '\0's ; Single newline ; = 16045690981402826360 decimal ; Return from print_int function Output The output of f your program should look something like this: 00000000000000000010 00000000000186562354 16045690981402826360 The leading Os on each number are fine. For a challenge, try to implement this using only loop for iteration (i.e., no jmp or jCC instructions). Assignment 1: Printing integers Right now, the only printing we can do is of fixed strings, by using the write syscall. We'll extend this by writing our own code to print 64-bit unsigned integer values. This essentially involves converting a binary value to decimal, using the same procedure we used to convert to binary/hexadecimal: divide repeatedly by 10 and look at the remainders. Converting binary to decimal As with converting decimal to binary, we divide repeatedly (by 10 this time) and use the remainders for the digits. E.g., to convert 101101b to decimal: Binary 101101b 5 100b Ob Remainder Decimal 4 BUFLEN: buffer: section .data _5 45 45 We stop when we get to O. Digits are written in reverse, from the right end of the string. In order to perform the conversion, we will need to pre-allocate a string buffer big enough to hold all the digits of the biggest unsigned 64-bit integer, 18446744073709551615, 20 characters: Home equ times BUFLEN db 20 0 ; Buffer of 20 '\0's (We could also use the .bss section, which is specifically used for uninitialized space, since we don't really need to fill the buffer with Os.) Your code should assume that the value to be converted is stored in register rdi, and the file number to write to in register rsi; it should construct the character representation in the buffer and then call the write syscall to print it to the file number in rsi. Use the following template for your program: section .data BUFLEN: buffer: newline: db section .text global start _start: equ times BUFLEN db mov rsi, 1 mov rdi, 10 call print int mov rsi, 1 mov rdi, 186562354 call print-int mov rsi, 1 mov rdi, 0xdeadbeef12345678 call print int ; End program mov mov syscall print-int: ret rax, 60 rdi, 0 ; Your printing code here 20 0 10 ; Buffer of 20 '\0's ; Single newline ; = 16045690981402826360 decimal ; Return from print_int function Output The output of f your program should look something like this: 00000000000000000010 00000000000186562354 16045690981402826360 The leading Os on each number are fine. For a challenge, try to implement this using only loop for iteration (i.e., no jmp or jCC instructions).
Expert Answer:
Answer rating: 100% (QA)
The images show an assignment that teaches how to print integers in assembly language specifically for 64bit unsigned integer values The exercise aims to extend printing capabilities from fixed string... View the full answer
Related Book For
Foundations of Financial Management
ISBN: 978-1259024979
10th Canadian edition
Authors: Stanley Block, Geoffrey Hirt, Bartley Danielsen, Doug Short, Michael Perretta
Posted Date:
Students also viewed these programming questions
-
Explain at least 3 ways Boccaccio would disagree with Horace. (the readings genealogy of the gentile" and "are poetica" Pick one level of Dante's Scheme for interpretation and explain, how his use of...
-
Lindsey Vonn sells real property for $315,000. The buyer pays $2,000 in property taxes that had accrued during the year while the property was still legally owned by Lindsey. In addition, Lindsey...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Factor by grouping. x 2 + 3x - 3y - xy
-
Compare and contrast the tax and financial accounting treatment of goodwill. Are taxpayers allowed to deduct amounts associated with self-created goodwill?
-
Maine Corporation buys motors for electric fans from another company that guarantees that at most 5% of its motors are defective and that it will replace all defective motors at no cost to Maine...
-
Journal entries for payroll A partial summary of the payroll data for Victoria Manufacturing Company for each week of June is as follows: a. Compute the missing amounts in the summary, assuming that...
-
Fosbre Corporations April 30 inventory was destroyed by fire. January 1 inventory was $150,000, and purchases for January through April totaled $500,000. Sales for the same period were $700,000....
-
Consider the region bounded by the curves. y 2 XML x = 2. x = 4, and y = 1. Set up, but do not solve an integral that will compute the volume of the solid obtained in the following ways: Show all...
-
Angela Green, an investment manager at Horizon Investments, intends to hire a new investment analyst. After conducting initial interviews, Green has narrowed the pool to three candidates. She plans...
-
15.- What right or obligation is associated with a long call?
-
Kaur Company opened a new store in February this year. During the first year of operations, the company made the following purchases and sales: Purchases Sales Date Units Cost / unit Date Units Price...
-
8. Evaluate: S 2 3et dt + 9 Round your answer to four decimal places.
-
. Use Excel to calculate the following measures Ford motor company and General Motors Ford motor company and General Motors Download the monthly prices for companies you chose and S&P 500 index...
-
A coupon bond has a face value of $1,000.with 5.55% coupon rate.It matures in 5 years,and has a yield to maturity of 9.75%.What is the price of the bond? Please submit your answers with 4 decimals...
-
Robert and Chris Jones are married and report AGI of $280,000 in 2023. They also provided the following information about their expenditures throughout the year: Doctor's visits for Chris 15,000 Over...
-
Question 4 Presented below is the Trial Balance and the Adjusted Trial Balance side by side for Walnut Creek Building Maintenance Company on December 31, 2020. Walnut Creek Building Maintenance...
-
Could a set of three vectors in span all of? Explain. What about n vectors in when n is less than m? R4
-
AI Quick, president of a Toronto Stock Exchange-listed firm , is very short-term oriented and interested in the immediate consequences of his decisions. Assume Mr. Quick is considering a project that...
-
Calculate the price of a bond originally issued six years ago that pays semiannual interest at the rate of 12 percent and matures in nine years at $1,000. The market currently requires an 8 percent...
-
For Nix Corporation, what is the tax savings due to amortization expense?
-
(Efficient frontier) This question relates to the data in the previous question. Calculate and graph the efficient frontier of the stock portfolios composed of stocks X and Y.
-
(Minimum variance portfolio) What will be the weights, the expected return, the variance, and the standard deviation of the minimum variance portfolio combining the stocks below? A B C 234567 X Y 3...
-
(Efficient frontier) This question relates to the data in the previous question. Calculate and graph the efficient frontier of the stock portfolios composed of stocks X and Y. A B C 1 RETURN...
Study smarter with the SolutionInn App