The algorithm of Figure 10.5 always produces a string of four characters independent of the sign and magnitude of the integer being converted. Devise an algorithm that eliminates unnecessary characters in common representations, that is, an algorithm that does not store leading 0s nor a leading + sign.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The algorithm of Figure 10.5 always produces a string of four characters independent of the sign and magnitude of the integer being converted. Devise an algorithm that eliminates unnecessary characters in common representations, that is, an algorithm that does not store leading 0s nor a leading + sign.

 

I have attached figure 10.5, can you please give me direction on how to solve this problem? Thank you! 

386
TETONNEAEG
01
02
03
04
05
06
07
08
09
ОВ
OC
OD
ОЕ
OF
10
11
12
13
14
15
16
89ABCDEF
1D
1E
1F
20
21
22
LNMHEENOGABLOONMASON 2008
chapter 10 A Calculator
: This subroutine converts a 2's complement integer within the range
: -999 to +999 (located in RO) into an ASCII character string consisting
of a sign digit, followed by three decimal digits, and stores the
: character string into the four memory locations starting at ASCIIBUFF
(see Figure 10.4).
;
BinarytOASCII ST
ST
ST
17 :
18
19
1A
1B
1C
2D
2E
2F
30
31
NegSign
;
Begin100
Loop100
;
End100
;
23
24 Loop10
25
26
27
28
29
2A
2B Beginl
End10
2C
32
33
34
ASCIIplus
35 ASCIIminus
36 ASCIIoffset
37 Neg100
38 Pos100
ST
LD
ADD
39 BtoA_Save0
3A BtoA_Savel
3B BtoA_Save2
BtoA_Save3
LD
STR
NOT
ADD
LD
LD
ADD
BRn
ADD
BRn
LD
STR
BRnzp Begin100
STR
LD
ADD
LD
ADD
BRn
ADD
BRnzp
End100
R2, R2, #1
BRnzp Loop100
STR
ADD
RO, BtoA_Save0
R1, BtoA_Savel
R2, BtoA_Save2
R3, BtoA_Save3
LD
ADD
STR
LD
R1,BtoA ASCIIBUFF : R1 keeps track of output string.
RO, RO,#0
: RO contains the binary value.
;
NegSign
R2,ASCIIplus
: First store the ASCII plus sign.
R2, R1,#0
LD
LD
LD
RET
R2, ASCIIminus
R2, R1,#0
RO, RO
RO, RO, #1
R2, ASCII offset
R3, Neg100
RO, RO, R3
R2, R1, #1
R3, Pos100
RO, RO, R3
RO.RO.#-10
End10
R2, R2, #1
Loop10
: First store ASCII minus sign.
: Convert the number to absolute
value; it is easier to work with.
Prepare for "hundreds" digit.
: Determine the hundreds digit.
: Store ASCII code for hundreds digit.
: Correct RO for one-too-many subtracts.
R2, ASCIIoffset: Prepare for "tens" digit.
: Determine the tens digit.
.FILL X002B
.FILL X002D
.FILL x0030
.FILL #-100
.FILL #100
.BLKW #1
.BLKW #1
.BLKW #1
.BLKW #1
30
3D BtoA_ASCIIBUFF .FILL ASCIIBUFF
Figure 10.5
Binary-to-ASCII conversion subroutine.
R2, R1. #2
Store ASCII code for tens digit.
RO, RO . #10: Correct RO for one-too-many subtracts.
R2, ASCIIoffset: Prepare for "ones" digit.
R2, R2, RO
R2, R1, #3
RO, BtoA_Save0
R1,BtoA_Savel
R2, BtoA_Save2
R3, BtoA_Save3
Transcribed Image Text:386 TETONNEAEG 01 02 03 04 05 06 07 08 09 ОВ OC OD ОЕ OF 10 11 12 13 14 15 16 89ABCDEF 1D 1E 1F 20 21 22 LNMHEENOGABLOONMASON 2008 chapter 10 A Calculator : This subroutine converts a 2's complement integer within the range : -999 to +999 (located in RO) into an ASCII character string consisting of a sign digit, followed by three decimal digits, and stores the : character string into the four memory locations starting at ASCIIBUFF (see Figure 10.4). ; BinarytOASCII ST ST ST 17 : 18 19 1A 1B 1C 2D 2E 2F 30 31 NegSign ; Begin100 Loop100 ; End100 ; 23 24 Loop10 25 26 27 28 29 2A 2B Beginl End10 2C 32 33 34 ASCIIplus 35 ASCIIminus 36 ASCIIoffset 37 Neg100 38 Pos100 ST LD ADD 39 BtoA_Save0 3A BtoA_Savel 3B BtoA_Save2 BtoA_Save3 LD STR NOT ADD LD LD ADD BRn ADD BRn LD STR BRnzp Begin100 STR LD ADD LD ADD BRn ADD BRnzp End100 R2, R2, #1 BRnzp Loop100 STR ADD RO, BtoA_Save0 R1, BtoA_Savel R2, BtoA_Save2 R3, BtoA_Save3 LD ADD STR LD R1,BtoA ASCIIBUFF : R1 keeps track of output string. RO, RO,#0 : RO contains the binary value. ; NegSign R2,ASCIIplus : First store the ASCII plus sign. R2, R1,#0 LD LD LD RET R2, ASCIIminus R2, R1,#0 RO, RO RO, RO, #1 R2, ASCII offset R3, Neg100 RO, RO, R3 R2, R1, #1 R3, Pos100 RO, RO, R3 RO.RO.#-10 End10 R2, R2, #1 Loop10 : First store ASCII minus sign. : Convert the number to absolute value; it is easier to work with. Prepare for "hundreds" digit. : Determine the hundreds digit. : Store ASCII code for hundreds digit. : Correct RO for one-too-many subtracts. R2, ASCIIoffset: Prepare for "tens" digit. : Determine the tens digit. .FILL X002B .FILL X002D .FILL x0030 .FILL #-100 .FILL #100 .BLKW #1 .BLKW #1 .BLKW #1 .BLKW #1 30 3D BtoA_ASCIIBUFF .FILL ASCIIBUFF Figure 10.5 Binary-to-ASCII conversion subroutine. R2, R1. #2 Store ASCII code for tens digit. RO, RO . #10: Correct RO for one-too-many subtracts. R2, ASCIIoffset: Prepare for "ones" digit. R2, R2, RO R2, R1, #3 RO, BtoA_Save0 R1,BtoA_Savel R2, BtoA_Save2 R3, BtoA_Save3
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education