QuestionQuestion

PART A
a) Write a procedure called DisplayHexDigit that takes as input a number between 0 and 15 stored in BX register and prints it in hexadecimal.

b) Write a procedure called DisplayHexByte that takes as input a number between 0 and 255 stored in BX register and prints it in hexadecimal. Procedure DisplayHexByte should call DisplayHexDigit to print the number.

c) Write a procedure called DisplayHexWord that takes as input a number between 0 and 65535 stored in BX register and prints it in hexadecimal. Procedure DisplayHexWord should call DisplayHexByte to print the number.

d) To test these procedures your main program should read a number from the input between 0 and 65535 and depending on the range that the input number falls call one of the above procedure.

Here are some sample execution scenarios:
C:\ASM>ass_2-2
0
0
C:\ASM>ass_2-2
15
F
C:\ASM>ass_2-2
16
10
C:\ASM>ass_2-2
255
FF
C:\ASM>ass_2-2
256
0100
C:\ASM>ass_2-2
1000
03E8
C:\ASM>ass_2-2
65535
FFFF

PART B
Problem:
1. Randomly generate a positive integer n (2<= n <=5).
2. Read n positive decimal integers from the standard input, store the n integers in an array and display
each integer on a separate line in hexadecimal format.
3. Use DumpMem function to display the contents of the corresponding memory locations.

Hints:
1. Use Randomize and RandomRange to generate a random integer n.
2. In a loop, use ReadInt to read each integer.
3. Use WriteHex to write each integer on the screen.
4. Use DumpMem to display memory contents.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

INCLUDE Irvine32.inc

.data
rndmsg BYTE "Generated random number is ",0
inpmsg BYTE "Enter next number: ",0
outmsg BYTE "Numbers of array in HEX format are:",0
memmsg BYTE "DumpMem called: ",0
array DWORD 5 DUP(0)
n DWORD 0
.code
main PROC

NEXT_RND:
mov eax, 6 ; set limit to 6 (because n <= 5)
call Randomize ;re-seed the random number generator
call RandomRange ;generate random number n
cmp eax, 2 ;check if n < 2
jb NEXT_RND ;if yes, loop until n >= 2

mov edx, OFFSET rndmsg ;print out the generated number, so we can see it
call WriteString
call WriteDec
call Crlf

mov n, eax ;save the number to memory location
mov ecx, eax ;initialize the counter for reading loop
mov esi, OFFSET array ;initialize the pointer
NEXT_INP:
mov edx, OFFSET inpmsg ;print out the instruction for input
call WriteString
call ReadInt ;read next number from console
mov [esi], eax ;store it in corresponding memory location of the array
add esi, 4 ;increment the pointer, so it points to the next element
loop NEXT_INP ;loop n times

mov edx, OFFSET outmsg ;print out the output notification
call WriteString
call Crlf

mov ecx, n ;initialize the counter for printing loop
mov esi, OFFSET array ;initialize the pointer...

By purchasing this solution you'll be able to access the following files:
Solution1.asm and Solution2.asm.

$10.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Assembly Language Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats