Write a program in object code that will convert a 3-bit binary number to a decimal number,For example, if input is 101, output should be 5; if input is 011, output should be 3. that is what I have to do,this is what I have so far but its not working, Can someone point out what is wrong or what need to be changed

49 00 30
D1 00 30
1C
F1 00 33
51 00 33
zz

Dani AI

Generated

A compact, practical note to clarify the approach and common pitfalls for a 3‑bit ASCII-to-decimal conversion on a Pep/8-style environment.

Do the conversion with a single accumulator and a left-to-right (MSB-first) algorithm: start acc = 0; for each input character (first, second, third) convert the character '0'/'1' to the numeric bit, then shift the accumulator left one place (multiply by 2) and add the bit. After three iterations acc will hold 0..7. Convert that final value to the display format your output routine expects (ASCII digit if the display routine prints characters).

Troubleshooting checklist:

  • Confirm the input instruction actually returns ASCII '0' or '1' (inspect the accumulator after a single read).
  • Convert character to numeric bit by subtracting the ASCII zero code before any arithmetic.
  • Clear the accumulator before starting the sequence.
  • Decide and be consistent about bit order (MSB-first vs LSB-first); test both if unsure.
  • Watch for extra characters (CR/LF) from the input routine; consume or ignore them.
  • Verify all load/store addresses match allocated data space and do not overlap.
  • Step through in the simulator and check the accumulator after each read/shift/add with simple test inputs 000, 001, 101, 111.

Notes on existing replies: @robertospartan is right to call out character encoding for display, and s shifting approach is a valid implementation choice — but you can usually avoid multiple stores by keeping the intermediate result in the accumulator. If you paste an assembler listing or a simulator trace (register values after each instruction), a line-by-line diagnosis can be supplied.

Member Avatar for Member #809393

which cpu? with objectcode alone we can't get far, however:
3 bits means that the numbers can be maximum 7
000 = 0 , 111 = 7 (add one bit more results in 4 bits numbers
adding 30h (48 decimal) to 3 bits numbers give you the ASCII result:
"0" = 30h, "001" = 31h etc
that ascii code you can use to put on screen. (if that is what you mean) much more conversion there is not, unless the 3 bit numbers must be seen as an larger octal number (base 8) but that wasn't the question.
I hope it is clear otherwise send an example of your code.

I uploaded a pic of what I use, I use the instruction specefier then I convert it to hexadecimal and write the objecet code

try this.
I didnt provide spaces on where to store them.

49 00    // read 1st char
49 00    // read 2nd char
49 00    // read 3rd char
d1 00    // load 1st to accum
80 00 30 // subtract 30
1c       // multiple by 2
1c       // multi by 2
e1 00    // store <-1st
c0 00 00 // make accum 0
d1 00    // load 2nd char
80 00 30 // sub 30
1c       // multiply by 2
e1 00    // store <-2nd
c0 00 00 // accum to 0
d1 00    // load 3rd
80 00 30 // subtract 30
e1 00    // store <-3rd
c0 00 00 // accum to 0
c1 00    // load address for 1st
71 00    // add 2nd
71 00    // add 3rd
e1 00    // save
39 00    // display
00
zz
         BR main

ans: .WORD 0x0000
num1: .BLOCK 2
num2: .BLOCK 2
num3: .BLOCK 2
main: LDA ans.d
DECI num2,d
ADDA num2,d
ADDA num2,d
ADDA num2,d
DECI num3,d
ADDA num3,d
ADDA num3,d
ADDA num3,d
SUBA num2,d
SUBA num2,d
SUBA num2,d
DECI num1,d
SUBA num1,d
SUBA num1,d
SUBA num1,d
STA ans,d
DECO sum,d
STOP
.END

Convert it into machine code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.