Question 1. Write a printString macro to print a text string of 8 characters, where each output character is separated by a space. The macro receives the address of the string.

Question 2. Write a procedure readInput that uses THE STACK for parameter passing. The procedure reads in a user input number and returns it to the caller. The procedure accepts an address of a prompt stringt, use the prompt string to prompt the user, then it reads in a user input number and returns it on the stack. You can assume that user input number will be a positive number that is within 1 byte.

Question 3. Write a procedure toBinary that uses REGISTERS for parameter passing. The procedure converts the user input number to a binary string, or a string of '1' and '0' characters. The procedure accepts the user input number and the address of the binaryStr in 2 registers. Then it converts the user input number into the appropriate binary characters and stores it in text string in main. The procedure should not modify the input registers.

Question 4. Complete the main procedure below so main calls the readInput and toBinary procedures, and then main invokes the printString macro to print the result.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

; The printString MACRO
; receives the address of the printed string

printString MACRO stringAddress
mov esi, stringAddress ; store the address of the string into esi register
mov ecx, 8 ; set ecx to 8, this is a loop variable
loop1: ; start a loop
mov eax, [esi] ; move char from address wher esi points to eax register
call WriteChar ; call WriteChar procedure which writes the character from al, the lowest 8 bit of eax register
mov al, 32 ; set al to 32, this is ASCII code for space
call WriteChar ;write space
inc esi; increment esi register to point to next character
loop loop1 ; repeat loop and decrement ecx, until ecx is 0
call Crlf ; call procedure to write an end of line

; The readInput procedure
; receives the address of the prompt string, and returns the input value in eax register

readInput PROC
push ebp ; store ebp register value on stack
mov ebp, esp; copy esp register value into ebp register
mov edx, [ebp + 8] ; set edx register to the third doubleword on stack, there is the address of prompt string
call WriteString ; Write the prompt string
call ReadDec ; call procedure to read a number into eax
pop ebp ; set ebp to its stored value
ret ; returns the eax value
readInput ENDP...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Get help from a qualified tutor
Live Chats