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

This assignment is in MASM For this assignment you will create a program that al

ID: 3823781 • Letter: T

Question

This assignment is in MASM

For this assignment you will create a program that allows a user to select a number base (in the range of 2 to 16, inclusive), enter digits for the number base, validate each digit as it is entered, and display the resulting value in base 2, 8, 10 and 16.

Requirements Create a program that: Has six user-defined procedures (UDPs):

o IsLegal – this UDP shall: Accept an ASCII value in one register. Accept a number base value in another register. Determines whether the ASCII value is valid for the base. Use the AsciiToDigit procedure Return 1 if the value is valid. Return 0 if the value is not valid.

o AsciiToDigit – this UDP shall: Accept an ASCII character value in a register. Returns the numeric value related to the ASCII character value. For example, if ‘A’ (41h) or ‘a’ (61h) is passed in, then this procedure would return 10d. Return -1 if the ASCII character is not valid.

o DigitToAscii – this UDP shall: Accept a numeric value in a register. Returns the ASCII character value related to the numeric value. For example, if 15d is passed in, then this procedure would return ‘F’ or ‘f’ (you must choose one case for letters). Return -1 if the numeric value is not valid.

o WriteInteger – this UDP shall: Accept a number in the EAX register. Accept a number base value in the BL register. Display the number in its base. For example, if 5 and 2 were passed in, this UDP would display 101. Use the DigitToAscii procedure. Not display leading zeroes.

o ReadInteger – this UDP shall: Accept a number base in the BL register. Read characters from the keyboard one character at a time until the user presses the Enter key. The valid characters are ‘0’ – ‘9’, ‘a’ – ‘f’ and ‘A’ – ‘F’. Validate each character, as it is entered, to ensure it is a valid character for the number base. For example, entry of ‘G’ for base 7 is invalid, but ‘6’ would be valid. If a character is valid, display it on the screen. If a character is invalid, then do not display it. Maintain a running final value as each character is entered. For example, if a user chose base 7 and entered the digits 2, 6, 7, A and1: o The 7 and A would be ignored leaving 2617. o Your running value would consist of calculating the decimal value of (2 * 72 ) + (6 * 71 ) + (1 * 70 ) = 141. Uses the AsciiToDigit procedure. Not use an array. Return the result in the EAX register. Return 0 if no valid characters were entered.

o DisplayIntegers – this UDP shall: Accept a number in the EAX register. Use the WriteInteger procedure to display number in its Base 2, Base 8, Base 10 and Base 16 equivalents.

Performs the following tasks in the main procedure:

o Prompts the user for a number base value. o

o Uses the ReadInteger procedure to get the base value from the user. If the ReadInteger procedure call results in 0 then you will exit the program. If the ReadInteger procedure call results in a value outside of the range of 2-16, then display an error message and prompt the user again.

o Prompts the user for a number. o Uses the ReadInteger procedure to get the number from the user.

o Uses the WriteInteger procedure to display the user-entered number in its Base 2, Base 8, Base 10 and Base 16 equivalents.

o Allows the user to enter another base/number combination.

Is formatted and commented

Does not use the .IF, .REPEAT, or .WHILE directives of MASM.

Irvine Procedure Calls: ReadChar WriteChar WriteString

Sample Program Input and Output: Enter base value (2 thru 16 or 0 to exit): 5 Enter a number in your chosen base: 1234 Base 2: 11000010 Base 8: 302 Base 10: 194 Base 16: C2 Enter base value (2 thru 16 or 0 to exit): 7 Enter a number in your chosen base: 1234 Base 2: 111010010 Base 8: 722 Base 10: 466 Base 16: 1D2 Enter base value (2 thru 16 or 0 to exit): 10 Enter a number in your chosen base: 1234 Base 2: 10011010010 Base 8: 2322 Base 10: 1234 Base 16: 4D2 Enter base value (2 thru 16 or 0 to exit): 16 Enter a number in your chosen base: 123abc Base 2: 100100011101010111100 Base 8: 4435274 Base 10: 1194684 Base 16: 123ABC Enter base value (2 thru 16 or 0 to exit): 0 Press any key to continue

Program Documentation Create your program document which contains: Algorithms as pseudo-code (C++ structure, but does not have to strictly adhere to the syntax of the language). A test plan and results. . A Unified Modeling Language (UML) Activity Diagram that shows how your program functions. Activity Diagram.

Explanation / Answer

.data
msg1:
.asciiz "Enter base value number in 2 (-2 to quit): "
msg2:
.asciiz " Answer: "
allOnes:
.asciiz "1111111111111111"
empty:
.space 16
newLine:
.asciiz " "
sum:
.space 16
sumMsg:
.asciiz " SUM: "
oneFound:
.asciiz " One present "
zeroFound:
.asciiz " Zero present "
.text
.globl main
main:

getNum:
li $v0,4 # Print string system call
la $a0,msg1 #"Please insert value (A > 0) : "
syscall

la $a0, empty
li $a1, 16 # load 16 as max length to read into $a1
li $v0,8 # 8 is string system call
syscall

la $a0, empty
li $v0, 4 # print string
syscall

li $t4, 0 # initialize sum to 0

startConvert:
la $t1, empty
li $t9, 16 # initialize counter to 16

firstByte:
lb $a0, ($t1) # load the first byte
blt $a0, 48, printSum
addi $t1, $t1, 1 # increment offset
subi $a0, $a0, 48 # subtract 48 to convert to int value
beq $a0, 0, isZero
beq $a0, 1, isOne
j convert #

isZero:
subi $t9, $t9, 1 # decrement counter
j firstByte

isOne: # do 2^counter
li $t8, 1 # load 1
sllv $t5, $t8, $t9 # shift left by counter = 1 * 2^counter, store in $t5
add $t4, $t4, $t5 # add sum to previous sum

move $a0, $t4 # load sum
li $v0, 1 # print int
syscall
subi $t9, $t9, 1 # decrement counter
j firstByte

convert:

printSum:
srlv $t4, $t4, $t9
la $a0, sumMsg
li $v0, 4
syscall

move $a0, $t4 # load sum
li $v0, 1 # print int
syscall

exit:
li $v0, 10 # exit system call
syscall

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