Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with this assignment.. it is for Linux assembly language x86 (YASM) Thank you Right now, the only printing we can do is

Please help me with this assignment.. it is for Linux assembly language x86 (YASM)

Thank you

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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 Remainder Decimal 101101b 5 -5 100b 4 45 Ob 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: section data BUFLEN: buffer: equ times BUFLEN db 20 0 ; Buffer of 20 'lo'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: equ times BUFLEN db db 20 0 10 ; Buffer of 20 '\0's ; Single newline section .text global -start -start: movrsi, 1 mov rdi, 10 call print_int movrsi, 1 mov rdi, 186562354 call print_int movrsi, 1 mov rdi, Oxdeadbeef 12345678 call print_int ; 16045690981402826360 decimal ; End program mov rax, 60 o mov rdi, syscall print_int: ; Your printing code here ret ; Return from print_int function Output The output of your program should look something like this: 00000000000000000010 00000000000186562354 16045690981402826360 The leading Os on each number are fine. Conditions Try to complete this assignment by only using the instructions mov, xor , syscall, the arithmetic instructions (add, sub, inc, dec, div, mul), and the loop instruction. (The template uses call and ret as well.) This assignment would be easier if you were allowed to use the test, branch, and conditional branch instructions (which we haven't talked about yet), but part of learning assembly is learning to work around arcane, arbitrary restrictions on what can and can't be done, so try to work within restrictions above, even if you've been reading ahead. An interesting challenge is to see how short you can make the print_int function, in terms of the length of its object code. For example, in my solution, print_int starts on address 0x37 (view the 1st file generated by asm to find the addresses of each instruction) and ends on address Oxao. Oxao - 0x37 = 105 bytes. See if you can beat that! 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 Remainder Decimal 101101b 5 -5 100b 4 45 Ob 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: section data BUFLEN: buffer: equ times BUFLEN db 20 0 ; Buffer of 20 'lo'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: equ times BUFLEN db db 20 0 10 ; Buffer of 20 '\0's ; Single newline section .text global -start -start: movrsi, 1 mov rdi, 10 call print_int movrsi, 1 mov rdi, 186562354 call print_int movrsi, 1 mov rdi, Oxdeadbeef 12345678 call print_int ; 16045690981402826360 decimal ; End program mov rax, 60 o mov rdi, syscall print_int: ; Your printing code here ret ; Return from print_int function Output The output of your program should look something like this: 00000000000000000010 00000000000186562354 16045690981402826360 The leading Os on each number are fine. Conditions Try to complete this assignment by only using the instructions mov, xor , syscall, the arithmetic instructions (add, sub, inc, dec, div, mul), and the loop instruction. (The template uses call and ret as well.) This assignment would be easier if you were allowed to use the test, branch, and conditional branch instructions (which we haven't talked about yet), but part of learning assembly is learning to work around arcane, arbitrary restrictions on what can and can't be done, so try to work within restrictions above, even if you've been reading ahead. An interesting challenge is to see how short you can make the print_int function, in terms of the length of its object code. For example, in my solution, print_int starts on address 0x37 (view the 1st file generated by asm to find the addresses of each instruction) and ends on address Oxao. Oxao - 0x37 = 105 bytes. See if you can beat that

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago