Register returning a hex value 1 higher than it should (8085 assembly) -


i working on assignment intro computer engineering class. trying write subroutine takes number input user , returns number in h register.

from can see, works fine single digit inputs when try continue on , add one, returns (input #)+1 in h register.

inputs not exceed 2 characters , not greater 20.

readn:  ; subroutine reads number digit user          ; , returns number in h         ; inputs: none         ; outputs: h register          push    b         push    psw         push    h          ; store registers in stack          mvi     b,0        ; 0 out b register          lxi     d,mess4    ; "enter number: $"         call    bdos       ; bdos = 0005  nextn:  mvi     c,1        ; c = 1 --> read character         call    bdos         cpi     cr         ; cr = 0dh (carriage return)         jz      lastn      ; if input carriage return --> go lastn          mvi     h,10       ; set h register multiplication          sui     '0'        ; subtract ascii 0 input, leaving numerical value         mov     e,a        ; store accumulator in e register         mov     a,b        ; bring b register (existing number) accumulator  mult:   add     b                   dcr     h          ; decrements multiplication tracker          jnz     mult       ; if h != 0 --> redo addition          add     e          ; add e register (new input) old input*10         mov     b,a        ; store result in b          jmp     nextn      ; redo input  lastn:  pop     h         mov     h,b         pop     psw         pop     b         ret 

can see might doing wrong here? hope provided everything, let me know if need clear code.

thanks!

it because:

        mov     a,b        ; bring b register (existing number) accumulator mult:   add     b                   dcr     h          ; decrements multiplication tracker          jnz     mult       ; if h != 0 --> redo addition 

you load accumulator b, it's b*1, loop runs 10 times , adds b*10 it, b*11. either run loop 9 times or start zeroed accumulator.

ps: learn use debugger.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -