How is it possible to check if a number is non-int in assembly language? My first thought was to check if there was a remainder or not
Asked
Active
Viewed 367 times
-4
-
4What format do you have it in? Obviously the general purpose registers can only contain integers and 8086 doesn't have an FPU. You might have it in text format in which case you only need to check for a decimal point (or an exponent if you support that). You can also have it as floating point in memory. – Jester May 01 '20 at 18:37
-
i need to find the avg of 4 ints and then store it in a memory location – Misu May 01 '20 at 18:57
-
Where are the integers coming from? Does the user type them? Are they hard coded in the program? – Seva Alekseyev May 01 '20 at 19:41
-
@SevaAlekseyev the user type them and then say they are stored in AX, and then i find the average of them – Misu May 01 '20 at 19:44
-
By the time they're in AX, you know for a fact it's an integer, since AX can't store anything else. The check if it's an integer should happen in the bit where you convert user input to an integer. How are you going to do that? User input comes in terms of characters (or even key codes). There must be some logic where you convert characters to numbers. – Seva Alekseyev May 01 '20 at 19:49
-
@SevaAlekseyev if we assume they were hardcoded ? – Misu May 01 '20 at 20:03
-
In assembly, when you hard code a number, you have to specify a datatype. So if it's hard-coded using a DD/DW/DB directive, it's definitely an integer. Maybe we're talking about different things. What do *you* think is a non-integer? – Seva Alekseyev May 01 '20 at 20:10
-
[edit] your question to include the necessary details that are currently only in comments. – Peter Cordes May 02 '20 at 02:21
1 Answers
2
For the average of 4 ints, if the sum of the 4 ints isn't a multiple of 4, then the exact result is not an integer, and the code will be rounding the result up or down. The sum of 4 ints may need to use a pair of registers to create a 32 bit sum to avoid overflow, then a check of the bottom 2 bits, then shrd + shr to shift the 32 bit sum into a 16 result.

rcgldr
- 27,407
- 3
- 36
- 61