ASM - String/Integer/ASCII/Base Convert In this lab assignment you will write a
ID: 646606 • Letter: A
Question
ASM - String/Integer/ASCII/Base Convert
In this lab assignment you will write a program that converts a stored integer into a string of a different base. In your main procedure you will use the string variable out_str to store the string. Based on the first letter of your last name:: Note the quotes (implying string). Also, notice the leading zeros. Converting an integer into a string can be performed in the following steps: 1. Load the integer into EDX:EAX. 2. Initialize a loop count into ECX. 3. Divide by the base. 4. Convert the remainder in EDX into ASCII. Note that ?0?=30h and ?A?=41h. 5. Write the remainder into the end of out_str[ECX-1]. 6. Erase EDX 7. Loop back to step 3. Procedure Make the conversion in the procedure num2str. The procedure must accept as input the value of the number to be converted and the offset of the out_str. The procedure doesn?t return any values in the stack frame. The procedure will convert the number to string and write it to memory using the offset passed through the stack frame. Testing and Validation Make sure you test thoroughly. Test if your program works for the largest number, smallest numbers, out of range numbers, etc. Report Follow the reporting style explained in your syllabus and required in the past labs. Also, make sure you: . Explain/derive the max size of bytes in out_str.Explanation / Answer
; Input: ; ESI = pointer to the string to convert ; ECX = number of digits in the string (must be > 0) ; Output: ; EAX = integer value string_to_int: xor ebx,ebx ; clear ebx .next_digit: movzx eax,byte[esi] inc esi sub al,'0' ; convert from ASCII to number imul ebx,10 add ebx,eax ; ebx = ebx*10 + eax loop .next_digit ; while (--ecx) mov eax,ebx ret ; Input: ; EAX = integer value to convert ; ESI = pointer to buffer to store the string in (must have room for at least 10 bytes) ; Output: ; EAX = pointer to the first character of the generated string int_to_string: add esi,9 mov byte [esi],STRING_TERMINATOR mov ebx,10 .next_digit: xor edx,edx ; Clear edx prior to dividing edx:eax by ebx div ebx ; eax /= 10 add dl,'0' ; Convert the remainder to ASCII dec esi ; store characters in reverse order mov [esi],dl test eax,eax jnz .next_digit ; Repeat until eax==0 mov eax,esi ret