Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Assignment 1: Printing integers Right now, the only printing we can do is of fixed strings, by using theUse the following template for your program: section .data BUFLEN: buffer: newline: db section .text globalOutput The output of f your program should look something like this: 00000000000000000010

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).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Foundations of Financial Management

Authors: Stanley Block, Geoffrey Hirt, Bartley Danielsen, Doug Short, Michael Perretta

10th Canadian edition

1259261018, 1259261015, 978-1259024979

Students also viewed these Programming questions

Question

Factor by grouping. x 2 + 3x - 3y - xy

Answered: 1 week ago

Question

a sin(2x) x Let f(x)=2x+1 In(be)

Answered: 1 week ago