assembly code help e. 16-bit to 32-bit unsigned number conversion - Input 16 bit
ID: 3595704 • Letter: A
Question
assembly code help
e. 16-bit to 32-bit unsigned number conversion - Input 16 bits unsigned number (for example, hexadecimal of fd) and convert this value to the identical value with 32-bit, show before and after the converted hexadecimal information and decimal information 16-bit to 32-bit signed number conversion - Input 16 bits signed number (for example, hexadecimal of fd) and convert this value to the identical value with 32-bit, show before and after the converted hexadecimal information and decimal information f.Explanation / Answer
Answer for (e):
For converting a 16-bit unsigned number to 32 bit, we just need to add 16 bit 0s in front of the 16 bit number.
Let us consider the 16-bit number(e.g. 1C15H) is stored in memory location 4000H as follows:
(4000H) = 15H'
(4001H) = 1CH
Also, we want to store the 32-bit result(converted number) in memory location 4002H as follows:
(4002H) = 15H
(4003H) = 1CH
(4004H) = 00H
(4005H) = 00H
The assemby code is given bellow:
LHLD 4000H : Get the 16-bit unsigned number in HL
SHLD 4002H : Store the 16-bit number in memory locations 4002H and 4003H
MVI H,00H : Move 00H in H
MVI L,00H : Move 00H in L
SHLD 4004 : Store 16-bit 0s in memory locations 4004H and 4005H
HLT
Answer for (f):
For converting a 16-bit signed number to 32 bit, we need sign extension. That is, if the sign bit of the number is 0 then we need to add 16 bit 0s in front of the number otherwise we need add 16 bit 1s in front of the number.
The assemby code is given bellow:
LHLD 4000H : Get the 16-bit unsigned number in HL
SHLD 4002H : Store the 16-bit number in memory locations 4002H and 4003H
MOV A,H : Move the higher order byte of the number (stored in H) to A
MVI H,00H : Move 00H in H
MVI L,00H : Move 00H in L
RAL : Rotate left the higher order byte of the number (stored in Accumulator) to get the sign in
carry flag
JNC SKIP : Just store 16 bit 0s if there is no carry (sign bit was 0)
MVI H, FFH : Store 8 bit 1s in H
MVI L, FFH : Store 8 bit 1s in L
SKIP: SHLD 4004 : Store 16-bit sign in memory locations 4004H and 4005H
Hope this code help you to get your answer.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.