flat assembler
Message board for the users of flat assembler.

Index > DOS > Numeric value stored in a Register reading as garbage

Author
Thread Post new topic Reply to topic
zir_blazer



Joined: 05 Dec 2006
Posts: 66
zir_blazer
I'm having serious troubles trying to get anything useful done with Ralf Brown's Interrupt List but everytime that I attempt to retrieve raw numbers from a Register, I get garbage instead. My code...

Code:
org 100h
mov [_8bits_integer],255 ; Fills 1 Byte (8 Bits Integer) in a Byte sized Memory Address
mov [_16bits_integer],65535 ; Fills 2 Bytes (16 Bits Integer) in a Word sized Memory Address
mov [_32bits_integer],4294967295 ; Fills 4 Bytes (32 Bits Integer) in a Double Word sized Memory Address
mov al,[_8bits_integer] ; Copies the 255 value to AL Register
mul [_8bits_integer] ; Multiplies the same 255 value by the 255 value stored in AL Register, should store result in AX Register
mov [_string],ax ; Copies the expected result (65025) to another Word sized Memory Address

mov ah,09h ; Sets AH Register to 09h for using with INT 21h
mov dx,_string ; Points the DX Register to the _string Memory Address
int 21h ; Should display the value stored in _string (65025)
int 20h ; Exit to DOS

label _8bits_integer byte ; Reserves 1 Byte?
db ?
label _16bits_integer word ; Reserves 2 Bytes?
db ?
label _32bits_integer dword ; Reserves 4 Bytes?
db ?
label _string word ; Reserves 2 Bytes?
db ?    


The _32bits_integer Memory Address isn't used, I placed it there for testing how much data I can store in a single Memory Address.
As the suspected reason for this to happened, I considered that the $ value that indicates than is the end of the string is nowhere to be found, but I don't know how to set it neither as none of my strings got a fixed value. So I tried with the other Register/DOS Interruption combination for displaying characters on screen, and the results where slighty better...


Code:
org 100h
mov [_8bits_integer],255 ; Fills 1 Byte (8 Bits Integer) in a Byte sized Memory Address
mov [_16bits_integer],65535 ; Fills 2 Bytes (16 Bits Integer) in a Word sized Memory Address
mov [_32bits_integer],4294967295 ; Fills 4 Bytes (32 Bits Integer) in a Double Word sized Memory Address
mov al,[_8bits_integer] ; Copies the 255 value to AL Register
mul [_8bits_integer] ; Multiplies the same 255 value by the 255 value stored in AL Register, should store result in AX Register

mov ah,02h ; Sets AH Register to 02h for using with INT 21h
mov dl,al ; Copies the first 8 Bits from AX Register to DL Register
int 21h ; Should display the value stored in the first 8 Bits from AX Register (No idea what it is)
mov dl,ah ; Copies the last 8 Bits from AX Register to DL Register
int 21h ; Should display the value stored in the last 8 Bits from AX Register (No idea what it is)
int 20h ; Exit to DOS

label _8bits_integer byte ; Reserves 1 Byte?
db ?
label _16bits_integer word ; Reserves 2 Bytes?
db ?
label _32bits_integer dword ; Reserves 4 Bytes?
db ?
label _string word ; Reserves 2 Bytes?
db ?    


This one display two ASCII characters (The one that looks like a face, and another one but white colored), that I suppose that are the closest thing to what I am actually seeking. Basically, what I am trying to do is monitoring the x86 Register values to know if the aritmethic operations that I do are calculated as I expect them to be, but in a way that I can read them. I plan later do something similar to know how Flags and SSE Registers reacts.
Any tips on how to do it the correct way is highly appreciated as this should be closely related to the reason why I can't display in a human-readable way the value that some DOS Interruptions assings to Registers.
Post 10 Dec 2006, 17:23
View user's profile Send private message MSN Messenger Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:

List but everytime that I attempt to retrieve raw numbers from a Register, I get garbage instead


As far as I can analyze the bug, you fail to convert the binary number to
a string. You name it "string", but do NOT convert it.

BASIC converts numbers for you, ASM/CPU doesn't.

One probably could do it with divisions like:
65'025\10 = 6'502, remainder 5
etc., maybe there are other ways to do.

Decimal output is NOT trivial in ASM. Hint: try HEX output first.

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 10 Dec 2006, 18:02
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
See my own bin2dec routine in C02.ASM if you want to convert to decimal (or hex or whatever). There are others (probably better), too.
Post 10 Dec 2006, 21:19
View user's profile Send private message Visit poster's website Reply with quote
zir_blazer



Joined: 05 Dec 2006
Posts: 66
zir_blazer
These routines probabily does what I'm needing, however, how I am supposed to add it effectively to my code and get the desired result? My knowledge in Assembler is minimal and I got no idea on how to interprete what the code does and how to use it.
By the way, what I want to see is the Register content, I don't care if it is in Binary, Decimal or Hexadecimal, just that it is in a human readable format (When I mean garbage, I'm talking about random symbols).
Post 11 Dec 2006, 00:14
View user's profile Send private message MSN Messenger Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:

These routines probabily does what I'm needing, however, how I am supposed to add it effectively to my code and get the desired result? My knowledge in Assembler is minimal


Mine also. But I got it working. See below.

Quote:

and I got no idea on how to interprete what the code does.


Neither do I. Just used the code as-is, only "crippled" EDI to DI. Do not ask
me how or why it works, but it seems to do for me. Smile Input integer is in
ESI, output in buffer, addressed by EDI/DI.

Code:
;Decimal output test
;DOS executable, requires 80386

format MZ
heap 0                   ; no additional memory
stack 4000h

magic1  equ     0a7c5ac47h 
magic2  equ     068db8badh 

    push cs
    pop ds

        jmp short @f

sillytext db 'Decimal test. (CL?) ??? by ???. This program is silly. It counts from 0 to 4294967295',0Dh,0Ah,0Dh,0Ah,24H 

@@:
        mov AX,0900h
        mov dx,sillytext
        int 21h

        mov di,labelend+4
        mov dword [labelend],0 ; start counting at 0
       
        mov byte [labelend+14],0Dh
        mov byte [labelend+15],0Ah
        mov byte [labelend+16],24h

@@:
        mov eax,[labelend]    
        mov esi,eax
        call near decout  ;convert
        mov AX,0900h
        mov dx,labelend+4
        int 21h           ;print to screen
        inc dword [labelend]
        jnz @b

        mov ax,4C00h ; exiting here after 2^32 loops Very Happy
        int 21h

;########################

decout:
        mov     eax,magic1
        mul     esi
        shr     esi,3
        add     esi,eax
        adc     edx,0
        shr     esi,20                  ;separate remainder
        mov     ebx,edx
        shl     ebx,12
        and     edx,0FFFF0000h          ;mask quotient
        and     ebx,0FFFFFFFh           ;remove quotient nibble from remainder.
        mov     eax,magic2
        mul     edx
        add     esi,ebx
        mov     eax,edx
        shr     edx,28
        and     eax,0FFFFFFFh
        lea     esi,[4*esi+esi+5]       ;multiply by 5 and round up
        add     dl,'0'
        mov     ebx,esi
        and     esi,07FFFFFFh
        shr     ebx,27
        mov     [di],dl
        add     bl,'0'
        lea     eax,[4*eax+eax+5]       ;mul by 5 and round up
        mov     [di+5],bl
        lea     esi,[4*esi+esi]
        mov     edx,eax
        and     eax,07FFFFFFh
        shr     edx,27
        lea     ebx,[esi+0c0000000h]
        shr     ebx,26              
        and     esi,03FFFFFFh       
        add     dl,'0'              
        lea     eax,[4*eax+eax]     
        mov     [di+1],dl          
        lea     esi,[4*esi+esi]
        mov     [di+6],bl
        lea     edx,[eax+0c0000000h]         
        shr     edx,26              
        and     eax,03FFFFFFh       
        lea     ebx,[esi+60000000h] 
        and     esi,01FFFFFFh       
        shr     ebx,25              
        lea     eax,[4*eax+eax]
        mov     [di+2],dl          
        lea     esi,[4*esi+esi]
        mov     [di+7],bl
        lea     edx,[eax+60000000h]
        shr     edx,25            
        and     eax,01FFFFFFh     
        lea     ebx,[esi+30000000h]
        mov     [di+3],dl   
        shr     ebx,24       
        and     esi,00FFFFFFh
        mov     [di+8],bl   
        lea     edx,[4*eax+eax+30000000h]
        shr     edx,24                  
        lea     ebx,[4*esi+esi+18000000h]
        shr     ebx,23                  
        mov     [di+4],dl
        mov     [di+9],bl
        ret              
;

labelend:

rb 100h

;END.

    

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 12 Dec 2006, 02:16
View user's profile Send private message Reply with quote
zir_blazer



Joined: 05 Dec 2006
Posts: 66
zir_blazer
That doesn't help me at all, as it is too hard for me to understand and I can't figure out what to do with it. I'm needing a well commented code that explain step-by-step how to retrieve readable data (I don't care that it is in Binary, Decimal or Hexadecimal for as long that it is not in machine code) instead of garbage when using DOS interruptions that writes data on Registers, and I can't manage to find something like this in the tutorial or source codes that I checked.
Post 14 Dec 2006, 19:21
View user's profile Send private message MSN Messenger Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
zir_blazer wrote:
That doesn't help me at all, as it is too hard for me to understand and I can't figure out what to do with it. I'm needing a well commented code that explain step-by-step how to retrieve readable data (I don't care that it is in Binary, Decimal or Hexadecimal for as long that it is not in machine code) instead of garbage when using DOS interruptions that writes data on Registers, and I can't manage to find something like this in the tutorial or source codes that I checked.


hello,
please read this reference,
[ DOS Frequently Asked Questions (FAQ) ]

you need to output integers to text screen,
also go here: i wrote a Sample code for Outputting integers

and here: Writing text Prints garbage, Need help
Post 04 Feb 2007, 08:56
View user's profile Send private message Visit poster's website Reply with quote
roboman



Joined: 03 Dec 2006
Posts: 122
Location: USA
roboman
I was working on that myself and just uploaded some sample code to the DexOS forum. It'd FASM, but writen for DexOS. http://jas2o.forthworks.com/dexforum/index.php?topic=232.0
Post 04 Feb 2007, 10:19
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.