[Solved]Right Printing Fixed Strings Using Write Syscall Ll Extend Writing Code Print 64 Bit Unsig Q37172181
Right now, the only printing we can do is of fixed strings, byusing the write syscall. We’ll extend this by writing our own codeto print 64-bit unsigned integer values. This essentially involvesconverting a binary value to decimal, using the same procedure weused to convert to binary/hexadecimal: divide repeatedlyby 10 and look at the remainders.
Converting binary to decimal
As with converting decimal to binary, we divide repeatedly (by10 this time) and use the remainders for the digits. E.g., toconvert 101101b to decimal:
BinaryRemainderDecimal101101b5_5100b4450b45
We stop when we get to 0.
Digits are written in reverse, from the right end of thestring.
In order to perform the conversion, we will need to pre-allocatea string buffer big enough to hold all the digits of the biggestunsigned 64-bit integer, 18446744073709551615, 20 characters:
section .dataBUFLEN: equ 20buffer: times BUFLEN db 0 ; Buffer of 20 ”s
(We could also use the .bss section, which is specifically usedfor uninitialized space, since we don’t really need tofill the buffer with 0s.)
Your code should assume that the value to be converted is storedin register rdi, and the file number to write to in register rsi;it should construct the character representation in the buffer andthen call the write syscall to print it to the file number inrsi.
Use the following template for your program:
section .dataBUFLEN: equ 20buffer: times BUFLEN db 0 ; Buffer of 20 ”snewline: db 10 ; Single newlinesection .textglobal _start_start: mov rsi, 1 mov rdi, 10 call print_int mov rsi, 1 mov rdi, 186562354 call print_int mov rsi, 1 mov rdi, 0xdeadbeef12345678 ; = 16045690981402826360 decimal call print_int ; End program mov rax, 60 mov rdi, 0 syscallprint_int: ; Your printing code here ret ; Return from print_int function
Output
The output of your program should look something like this:
000000000000000000100000000000018656235416045690981402826360
The leading 0s on each number are fine.
Conditions
Try to complete this assignment by only using theinstructions mov, xor, syscall, the arithmetic instructions (add,sub, inc, dec, div, mul), and the loop instruction. (The templateuses call and ret as well.) This assignment would beeasier if you were allowed to use the test, branch, and conditionalbranch instructions (which we haven’t talked about yet), but partof learning assembly is learning to work around arcane, arbitraryrestrictions on what can and can’t be done, so try to work withinrestrictions above, even if you’ve been reading ahead.
An interesting challenge is to see how short you can make theprint_int function, in terms of the length of its object code. Forexample, in my solution, print_int starts on address 0x37 (view the.lst file generated by asm to find the addresses of eachinstruction) and ends on address 0xa0. 0xa0 – 0x37 = 105bytes. See if you can beat that!
Expert Answer
Answer to Right now, the only printing we can do is of fixed strings, by using the write syscall. We’ll extend this by writing o… . . .
OR

