Answer the question
In order to leave comments, you need to log in
Why is the wrong result shown for a certain value of the entered number?
And again, the assembler, with an even number 8, gives the result 767, but I don’t understand why ... here is that part of the code (the entered value in al)
push ax
call Calculation
Calculation:
test al, 1
jnz Odd ;нечетное, переход на метку Odd
jz Even ;четное, переход на метку Even
Odd:
push bp
mov bp,sp
mov al,[bp+4]
mul al
pop bp
jmp Show_AX
Even:
push bp
mov bp,sp
mov al,[bp+4]
mov bl, al
mul al
mul bl
sub al, 1
pop bp
Answer the question
In order to leave comments, you need to log in
No, that's right, you have 767 and should work, judging by your code.
8 * 8 * 8 = 512
512 + byte(0 - 1) = 512 + 255 = 767
let me translate your code into C for clarity
int Calculation(short value) {
if (value % 2 == 1) {
char value_l = (char)value; // use only lower 8 bit
return value_l * value_l;
} else {
char value_l = (char)value; // use only lower 8 bit
short first_mul = value_l * value_l;
char mul_l = (char)first_mul; // use only lower 8 bit of result
short second_mul = mul_l * value_l;
second_mul = (second_mul & 0xFF00) + (char)second_mul - 1; // subtract 1 only from lower 8 bits
return second_mul;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question