I am new to assembly language and I am taking a course on it right now. I have a question on how you suppress leading zeros when it displays to the screen.

Posted on 2006-11-25 21:47:57 by 33w
Depends on what method you are using to "display to the screen."

There are plenty of methods, including BIOS Interrupts, DOS Interrupts, Win32 API Library calls, Linux Kernel API via INT 0x80 and writing directly to video memory to name a good few x86-based ones.

Let us know what method you are using, and then we can possibly advise you on solutions to your problem.
Posted on 2006-11-25 22:16:56 by SpooK
Thanks for the response,

I don't want to try to get my homework done here, I really am trying to learn this. Can you tell me if I am thinking along the right path.This is where the code is at. I am thinking that I would compare what is in HUN and if it is a zero then I would jump to display a blank.

.model small
MSG    DB    'The number is '
HUN    DB    ?
TEN    DB    ?
ONE    DB    ?
BLANK DB    ' '              ; I added this so I could make it print a blank in place of a zero
        DB    0DH,0AH,'$'
        CALL  BTOD
        LEA  DX,MSG 
        MOV  AH,9
        INT  21H

        MOV  AL,BINVAL  ;load binary input value
        SUB  AH,AH      ;prepare for division by 100
        MOV  BL,100
        DIV  BL          ;get hundreds digit
        ADD  AL,30H      ;convert into ASCII digit
      MOV  HUN,AL      ;and save
        CMP  HUN,0   ;see if it is zero This is where I think I should compare it to zero then jump
        JZ    BLANK   ; jump to blank

The code goes on to get the tens digit and ones digit. I also have a question on when it displays. In the .data section I am identifying my data. When it runs through the code it prints .

The number is 026.
What exactly is telling it to print HUNTENONES after "The number is".  Is it the DB    0DH,0AH,'$' statement that is saying to add these right after the statement

Thanks for the help.

Posted on 2006-11-26 10:35:11 by 33w
or maybe I should look at putting it here.

        CALL  BTOD
        CALL  SUPP  ;need to compare my digits to zero and suppress
        LEA  DX,MSG 
        MOV  AH,9
        INT  21H

JZ NOTH  ;now I need to figure how to suppress

Would this be a more efficient place to do it?

Posted on 2006-11-26 11:59:55 by 33w
Strings with predefined terminators, such as '$' for the DOS Interrupt you specified, are easier to deal with since they rely on sequential string access up to the point of the string terminator.

To put simply, you need to detect leading zeros in your string prior to calling the Interrupt. You can simply check the BYTE value at DS:DX and increment DX for each instance of '0' (30h in ASCII) you find. You must also check for the string terminator, '$', yourself, as you cannot assume that the string doesn't contain only zeros (safe programming practices).

Steps to Achieve this (SUPP)
-Load DX with the address of the String
-Check DS:DX for 30h (ASCII zero)
-Increment DX for each 30h (ASCII zero) you find, stop when you don't find anymore
-Determine if the last DS:DX value you found is the String Terminator ('$'), handle such an error appropriately
-Return from function accordingly
Posted on 2006-11-26 12:10:54 by SpooK

I finally got my code to work

Posted on 2006-11-26 16:05:50 by 33w