Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

help, on addition and substraction with user inputs

help, on addition and substraction with user inputs

help, on addition and substraction with user inputs

Im trying to create calculator...but rt now just trying the addition and subtraction numbers with user input. Im using 16 bits DOS  o/s.  I can sure used some help. This is part of my codes...

my add and sub code is not function correctly.


mov dx, userinput
call   Writestring
call   Readint
call   Crlf
mov  bx,10
call   Crlf
mov  al, userinput

;user input operation proc(-,+,/,*):

mov dx, offset operator
call  Writestring
call Readstring

ja   opercmp      ; jump to operation procedure

; operation proc

   cmp    al,43    ; value for + sign
  je        add1    ;  add1 label proc

  cmp   al,45
  je      sub1       ; sub1 label

;storage1 the value


   cmp  storage1,0
  jne     stor2
  mov stor1,al
  jum  input

;storage2 value

  mov storage2, al
  jmp   input

addition proc:


          push bx
          push cx
          mov ax,0
cs1:    add ax,[bx]
          add bx, 2
         loop    cs1
         pop    cx
        pop     bx

addition endp

subtraction proc:


          push bx
          push cx
          mov ax,0
cs2:    sub ax,[bx]
          sub bx, 2
         loop    cs2
         pop    cx
         pop     bx

subtracition endp

RE: help, on addition and substraction with user inputs


Its a bit difficult to see how you are storing your input numbers.

Is the input string stored in memory packed to the right? this means that the fixed location of the string will always be the lowest denominator (x1 and not x10).

This will make it easier to convert the input string into binary. You have to decide if the binary number will be a signed or unsigned integer or floating point number.

I suggest you convert the number into a signed integer as this will enable you to take advantage of the processor calculating the results correctly first hand. a signed integer has its highest bit on for a minus number.

If you store the string normally you can write a routine to find the end and then read it backwards. each digit you read is then multiplied by its denominator and added to the total. if at the end you find a minus sign i suggest you subtract the total from zero to give you a twos comliment negative number.

Thats how to convert a decimal number but you can convert any type of number into binary. once in binary the calculations are easy.

are you converting your numbers into binary correctly?

in your routines-
you are adding every consecutive word from starting from[BX], the number of consecutive words to add in CX.

word=2 bytes
[ ] = location in memory, [BX]=location pointed by BX

have you set BX to point to your stored variables corrctly?

I cant see where you set CX, how many consecutive words do you want to add?

i notice when you 'ADD' the memory pointer BX moves up memory and when you 'SUBTRACT' it moves down.

you can only use RET command if the procedure is called! i would try somting like this:

you had:
        cmp     al,43    ; value for + sign
        je      add1     ; add1 label proc
        cmp     al,45
        je      sub1       

i suggest:
        cmp     al,43
        jne     notadd
        call    add1
        jmp     notsub
notadd: cmp     al,45
        jne     notsub
        call    sub1

if all your procedures preserve registers then you can remove 'jmp notsub' doing this will save memory but not speed.

remember when you use mul and div the DX register is also used. especially using div, DX must be the high word of the value to be divided, DX must be set to zero if the number fits into AX.

you can use EAX, EBX ect in 16bit real mode. this will allow you to have larger signed integers.

I would only worry about floating point binary numbers if you are interested in calculus or trigonometry etc.


The people who have nothing to say and say it too loud have little knowledge, It's the quiet ones you need to worry about!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close