Subroutines problem Subroutines problem Guest (visitor) (OP) 29 Mar 02 13:49 how do i read an 8-bit integer n from the keyboard and thanread 16-bits integer X from the keyboard. then calculate the sum s = x/1 + x/2 + x/3 + x/4 ....+ x/n; (using quotient only) RE: Subroutines problem AmkG (Programmer) 30 Mar 02 05:39 Use CJust kidding.First, all inputs are in stringsSecond, learn how to convert strings to integers.Third, learn how to loop.Fourth, have fun.Fifth, good luck! "Information has a tendency to be free. Which means someone will always tell you something you don't want to know." RE: Subroutines problem Guest (visitor) (OP) 1 Apr 02 19:22 that wasn't any help! i need code ...or at least give me the code for 8-bit integer input? RE: Subroutines problem AmkG (Programmer) 1 Apr 02 22:45 Like I said:All inputs are in strings of charactersALWAYSSO: First, learn to convert a string representation of a number to an integerWhen a user enters the number 123, your program will ALWAYS get the following numbers:31h, 32h, 33hWhich are the ASCII representations of the string of numbers that he input.The quick and dirty way to convert a string to a number is to AND the ASCII inputs with 0fh.But you would still have three numbers: 1h, 2h, and 3h.So next, learn to multiply by 10So here's the loop:number=0loop1:Get a charactercheck if carriage return or termination, if so get outAND char with 0fhnumber=number*10add char to numberloop againThat's pseudo code. If you can't convert pseudo code to actual code, I suggest you try something easier.That pseudo code will work with n-bits.Also: If you use the OS's get a character function, then you won't be able to use a backspace feature. If you want, use your OS's string input function, then replace the Get a Character line with something like:mov char,StringBuff[index]index++And of course clear the index before looping.As for the second part where you have to divide: Division is very bad for the processor. I can't understand why I get division errors so often. I try to avoid division because I crash my computer too much with it. 'Course you can do multiplication by reciprocal.n/d = ( n * (10000h / d) ) /10000h = ( n * (10000h / d) ) >> 16For example: to divide by 2, multiply a 16-bit number by 8000h (That is 10000h / 2). This results in a 32-bit number. Get the high 16-bits, which is the result you would get if you divided. Multiplication is faster after all.BUT how would you get the value 10000h/d? You precalculate it! Since the divisor goes only up to 0ffh, you can just bring out your calculator and divide 10000h by all values of d up to 255, and store them in a table. It's just a couple of hour's work...But that's rather complicated. You can just try to use idiv which I think is more stable than div. "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."