Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in LC-3 assembly language that converts input decimal values int

ID: 3672712 • Letter: W

Question

Write a program in LC-3 assembly language that converts input decimal values into 16-bit binaries given the flow chart below.

Read in a string and convert it into a two's complement binary integer and then print out the binary representation. Start MASK FILL x8000 FILL 24000 FILL x2000 int 0 flag = 0 GETC flag= 1 yes MASK x8000 x4000 x2000 is char no is char no digit-char-48 int-int x 10 + digit yes is flag yes int !int int-int1 no 1st MASK address count= 15 is count no yes Load MASK digit-int AND MASK is digit 0 Print 0 yes no MASKptr = MASKptr + 1 count- count -1 End Print "1" Note: This flow chart assumes the user only enters a first, if at all, and then only 0-9, ended with an 'enter" key

Explanation / Answer

main PROC

mov edx, OFFSET msgBinaryToDecimal   ; " Binary to Decimal Converter in Assembly Language "

call WriteString                     ; Display a null-terminated string.

call Crlf                            ; Writes an end-of-line sequence to the console window.

mov edx, OFFSET msgBinary

call WriteString

mov edx,OFFSET binaryNumber

mov ecx,SIZEOF binaryNumber  ; Specify length of binaryNumber

call ReadString              ; Reads a string from the keyboard, terminated by the Enter key.

mov dBinaryNumberLength,eax  ; Number of characters read

; Find Decimal Number

mov eax,0

mov esi,0                             ; ESI  initialize with zero

mov ecx, dBinaryNumberLength          ; ECX  initialize with length of Binary Number

whilePart:

cmp ecx,0                       ; Compare ECX and 0

je displayDecimalNumber         ; Jump if equal  (==)

mov dOuterLoopCount,ecx         ; Copy ECX Value in dOuterLoopCount

ifPart:

cmp binaryNumber[esi],'0'         ; Compare binaryNumber[esi] and '0'

je whilePartNext                  ; jump if equal (==)

;Multiplying by zero, equal to zero. do nothing in this case

elseIfPart:

cmp binaryNumber[esi],'1'         ; Compare binaryNumber[esi] and '1'

jne elsePart                      ; jump if not equal (!=)

;Calculate dDecimalNumber += 1 * pow(wBase, dBinaryNumberLength - ESI - 1);

mov ecx, dBinaryNumberLength

sub ecx,esi

dec ecx

; Calculate Power

mov eax,1       ; EAX initialize with 1

whilePart2:

cmp ecx,0   ; Compare ECX and 0

je stop     ; jump if equal (==)

; Multiply EAX and BX and save result in EAX

mov bx,wBase

mul bx

dec ecx

jmp whilePart2

stop:

add dDecimalNumber,eax

jmp whilePartNext

elsePart:

mov edx, OFFSET msgNotBinary  ; " Invalid Binary Number, Binary Number Contains only 0's or 1's"

call WriteString

call Crlf       ; Writes an end-of-line sequence to the console window.

call WaitMsg    ; Displays a message and waits for a key to be pressed.

exit            ; The exit statement (indirectly) calls a predefined

        ; MS-Windows function that halts the program.

whilePartNext:

inc esi

mov ecx,dOuterLoopCount ; Replace value of ECX with dOuterLoopCount

dec ecx

jmp WhilePart

displayDecimalNumber:

mov edx, OFFSET msgDecimalNumber

call WriteString

mov eax, dDecimalNumber

call WriteDec              ; Display an unsigned 32-bit integer value

                                   ; in EAX in decimal format.

call Crlf

call WaitMsg    ; Displays a message and waits for a key to be pressed.

exit            ; The exit statement (indirectly) calls a predefined

                    ; MS-Windows function that halts the program.

main ENDP  ; The ENDP directive marks the end of the main procedure.

END main       ; The END directive marks the last line of the program to be as

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote