0

I got Integer overflow in HLA nasm. I would like to write simple program that divide provided Distance variable by 15000 and display evaluation of it, but I faced that problem. I simply don't understand an idea of division in HLA. Thank you in advance for your help.

program zad2;
#include( "stdlib.hhf");

static
    f    :  int32   := 15000;
    s    :  int32   := 300000;
    Distance: int32;

begin zad2;

        stdout.put("Give car distance", nl);
        stdin.get(Distance);
        if (Distance<150000) then
            MOV(15000, eax);
            div(Distance, EDX:EAX );
                stdout.put("div evaluation:",eax ,nl);
                    jmp menu0;
            endif
end zad2;
philippe lhardy
  • 3,096
  • 29
  • 36
RMachnik
  • 3,598
  • 1
  • 34
  • 51

3 Answers3

2
mov(0, edx)
mov(15000, eax);
div(distance, edx:eax);

You need to zero extend into edx because it's the register that holds your remainder.

prexcel2215
  • 33
  • 1
  • 7
0

I found my resolution of it. Please have a look on it. All stuff with hla div are not working correctly on Windows version of hla compiler. It should look like this. I hope it might by somehow helpful for sb ;)

mov(Distance, eax);
mov(15000, ebx);
div(ebx);
mov(eax, age);
RMachnik
  • 3,598
  • 1
  • 34
  • 51
0

I have also been researching Div use with HLA (High Level Assembly). I wanted to share what I found also to help others. This program was not a class assignment, for that we had to do everything by hand and show our work. I just wrote this short program for some extra practice, so I thought why not share it, it worked great for checking my work, plus it has division use in it. This program will take a char convert it to Hex to Decimal and after convert it to binary, to do the binary conversions is uses idiv inside of a while loop and goes from 64 to 32 to 16 to 8 to 4 to 2 to 1 each while loop iteration divides the cl in half.

    //Jonathan Lee Sacramento State University
    //CSC35
    //Professor Devin Cook
    //Feb 11 2023
    //Non-Credit Practice program with Asci/hex/decimal

    //Program: This is a HLA program that converts ASCII/HEX/DECIMAL/BINARY 
    based off one letter input

    program binarydiv;
    #include( "C:\hla\include\stdlib.hhf"); 

    static
        UserChar: char;
        i8:  int8 :=0; //value

    begin binarydiv;
        stdout.put("---> Please enter one character: ");
        stdin.get(UserChar); //store as char
        stdout.put("You Entered: ",UserChar);
        mov(UserChar,al); // store hex value of char into al reg
        stdout.put(nl,"(",UserChar,") In Hex is: ", al); //show hex value
        mov(al,i8); //move hex into int8 
        stdout.put(nl,"(",UserChar,") In Decimal is: ",i8); //show decimal value
        stdout.put(nl,"(",UserChar,") In Binary is: 0"); //start of binary not using 128
        mov(64,cl); //use cl with operators 2nd binary
        while(cl>0) do
            if(i8>=cl) then 
                stdout.put("1");
                sub(cl,i8);
            elseif(i8<cl) then
                stdout.put("0");
            endif; 
    //div block
            mov(cl,al);
            cbw();
            mov(2,bl);
            idiv(bl);
            mov(al,cl);
    //end div block
        endwhile;
        stdout.put(nl);
    end binarydiv;

program running with use of idev

  • 1
    With a prompt like "Please enter one letter A-Z or a-z:", it is confusing to see that your program does in fact accept inputs like "3" and "5". Wouldn't it have been nicer to prompt the user with "Please enter any character:" ? – Sep Roland Feb 12 '23 at 19:20
  • 1
    Is is necessary to clear AL beforehand? Couldn't you simplify `mov(0,al);` `add(UserChar,al);` into `mov(UserChar,al);` ? – Sep Roland Feb 12 '23 at 19:24
  • Thanks for the reply. I was testing other things we learned in class, I have corrected this. – Jonathan Lee Feb 13 '23 at 03:40