flat assembler
Message board for the users of flat assembler.

Index > Main > variables losing data grrrr...

Author
Thread Post new topic Reply to topic
robertkey60



Joined: 09 Jan 2008
Posts: 6
robertkey60 09 Jan 2008, 19:49
if i code "name DB 0B" as a variable in the data segment,it is in the listing file but in the final EXE,the address is wrong,regardless of "org" directive. please post if need mo info
Post 09 Jan 2008, 19:49
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 09 Jan 2008, 19:51
name db 0b?
without context, no one can help you...
Post 09 Jan 2008, 19:51
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 09 Jan 2008, 20:14
if your problem is that when you do "mov byteReg, [name]" you get a zero in the register that is because you specified 0b (zero using binary radix). If you want value 11 in hex use "$b" or "0xb" or "0bh". Be careful with "0d" also since it means zero using decimal radix.
Post 09 Jan 2008, 20:14
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 09 Jan 2008, 20:50
> is because you specified 0b (zero using binary radix).

Sad http://board.flatassembler.net/topic.php?t=7661 Sad

$ is the safest for hex ... btw, it would be cool if I could prefix binary numbers as well Idea , instead of stupid "b" at the end that might appear or not Neutral
Post 09 Jan 2008, 20:50
View user's profile Send private message Reply with quote
robertkey60



Joined: 09 Jan 2008
Posts: 6
robertkey60 09 Jan 2008, 21:57
hmm that may have been a bad choice for example,here is my source file fragment


_HEXTABLE DB 00h,01h,02h,03h,04h


start:

lea bx,_HEXTABLE


end start





the data actually appears in the exe file but at a` different offset than supplied by "lea" or the listing. as you can tell im new at ass' but none of my 5 books say anything about this sort of thing.
Post 09 Jan 2008, 21:57
View user's profile Send private message Reply with quote
robertkey60



Joined: 09 Jan 2008
Posts: 6
robertkey60 09 Jan 2008, 21:57
and it is in the .data seg ,sorry
Post 09 Jan 2008, 21:57
View user's profile Send private message Reply with quote
robertkey60



Joined: 09 Jan 2008
Posts: 6
robertkey60 09 Jan 2008, 22:08
can i post my source and listing?
Post 09 Jan 2008, 22:08
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 09 Jan 2008, 22:16
.

Quote:

start:
lea bx,_HEXTABLE
end start


1. Seems to be MASM syntax and this might be your main problem.

2. No need for lea, just mov bx,_HEXTABLE

Quote:
the data actually appears in the exe file but at a` different offset than supplied by "lea" or the listing. as you can tell im new at ass' but none of my 5 books say anything about this sort of thing.


This is a FLAT assembler Shocked ... the "data" appears in the exe there where you place it in your source. Please read http://flatassembler.net/docs.php?article=design Idea Your 5 books (together 100 years old ?) might not know anything about FASM Neutral

{2nd post} > and it is in the .data seg ,sorry

{3rd post} > can i post my source and listing?

1. Here you can edit your posts Idea

2. NO, check out MASM vs FASM design first Idea
Post 09 Jan 2008, 22:16
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 09 Jan 2008, 23:14
{3rd post} > can i post my source and listing?

no, it's absolutlly forbiden, if you make this, you expose yourself to justice problems, Laughing

sure you can, you shall, you must, we need the source to know exacttly what is the problem, the problem can be a little byte somewhere, or a wrong label reference.
please, post your source.
Post 09 Jan 2008, 23:14
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 09 Jan 2008, 23:21
Of course you can, and also post minimal source code showing the undesired effect if possible (actually it is desired the source code rather than assembler generated listing).

The only problem I can think of now is that DS is not set to the segment that holds the table but post the source so we can tell you how to fix all this.
Post 09 Jan 2008, 23:21
View user's profile Send private message Reply with quote
robertkey60



Joined: 09 Jan 2008
Posts: 6
robertkey60 09 Jan 2008, 23:35
Code:
;    THIS FILE READS AND DISPLAYS THE BIOS-PARAMETER-BLOCK 
;    FROM THE BOOT SECTOR OF A FLOPPY DISK







.model small
.data
  
  ; BIOS-Parameter-Block from floppy                                               
                                             
  __SECTOR_BUFFER         DB 512 DUP (0)     ; -a 512 byte array to hold a sector
  __BPB_ASCII_BUFFER      DB 138 DUP (0)     ; -make a routine to copy the BPB 
                                             ; into this,and then go back thru
                                             ; it and convert to ASCII for display
                                             
                                             
  __BYTES_PER_SECTOR      DW 00              ; at offset 0B,the start of BPB
  __SECTORS_PER_CLUSTER   DB 00              ;  
  __RESERVED_SECTORS      DW 00
  __NUMBER_OF_FATS        DB 00
  __ROOT_DIRECTORY_TOTAL  DW 00               ;MAX # OF ENTRIES ALLOWED  
  __SECTORTOTAL_COUNT     DW 00               ;total on this diskette
  __MEDIA_DESCRIPTOR      DB 00
  __SECTORS_PER_FAT       DW 00
  __SECTORS_PER_TRACK     DW 00
  __HEADS_TOTAL           DW 00               ;SIDES ON DISK
  
  __BPB_ENTRY_SIZE        DB 2,1,2,1,2,2,1,2,2,2,1 ;INCOMPLETE
    
  
    SectorsPerFat         DB  "Sectors Per FAT : "


  __BIOS_PARAMETER_OFFSET EQU 0Bh


   _BPS                   EQU "Bytes Per Sector"               
   
   _BUFFER                DW 00
    DBFR_PTR              DW 00
    DBFR_BASEPTR          DW 00

   _TABLE_POINTER         DW 00
   _TABLE_OFFSET          DB 00
   _HEX_TABLE             DB 00h,01h,02h,03h,04h,05h,06h,07h,08h,09h,0ah,0bh,0ch,0dh,0eh,0fh  ;short version,finish as needed
    HEXTBL_BASEPTR        DW 00h
    HEXTBL_PTR            DW 00h
   _ASCII_TABLE           DB 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h,41h,42h,43h,44h,45h,46h  ;displays 0-9 a-f to screen
    ASCII_TABLE_BASEPTR   DW 00h
    ASCII_TABLE_PTR       DW 00h

.code
        org 100h




;*************************************************************************
;                      MY MACROS
;*************************************************************************
SAVE_REGISTERS MACRO
push ax
push bx
push cx
push dx

push ds
push es
ENDM SAVE_REGISTERS

RESTORE_REGISTERS MACRO
pop ax
pop bx
pop cx
pop dx

pop ds
pop es
ENDM RESTORE_REGISTERS

SPLITAX MACRO
xor ah,ah
xor cx,cx
mov ah,al
mov cl,04
shl al,cl
shr ah,cl
shr al,cl
ENDM

SPLITDX MACRO
xor dh,dh
xor cx,cx
mov dh,dl
mov cl,04
shl dl,cl
shr dh,cl
shr dl,cl
ENDM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;




START:     ;#############       Entry Point       #########################




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

;Entry Point ------>
        
        call READ_BOOT_SECTOR
        call CLEAR_BPB_ASCII_BUFFER
        call FIL_BPB_ASCII_BUFFER

             lea bx,__BPB_ASCII_BUFFER
        call CONVERT_TO_DISPLAYABLE




jmp EXIT_TO_DOS



TESTS PROC

ret
ENDP       
           
           
           ;sector has been read into memory at 0:7c00 so just go there 
                                           ;otherwise read it into a buffer;
           ;and advance to offset 3 and copy it into the high-byte of ax
           ;variable and then increment and read in offset 4 into the 
           ;low-byte of ax,then copy ax into the __BYTES_PER_SECTOR variable

        
        
        
READ_BOOT_SECTOR PROC
;       [reads the boot sector into the sector buffer]

        cli
        xor ax,ax
        xor dx,dx
        mov dl,00h
        int 13h             ;reset Diskette
        
        xor ax,ax
        xor bx,bx
        xor cx,cx
        xor dx,dx
        lea bx,[__SECTOR_BUFFER]

                            ;begin int 13 "read-diskette-sector" call-setup
        
        mov ah,02h          ;select sub function "read-diskette-sector"
        mov al,01h          ;how many sectors to read in
        mov ch,00h          ;track #,0 for boot-sector
        mov cl,01h          ;sector #,starting at 1
        mov dh,0            ;head #
        mov dl,0            ;Drive #
                        
                        ;es:bx=pointer to buffer,has to be done for exe
        int 13h         ;do it eh?
                        ;for now,assume "NO ERRORS"

        ret
ENDP   

CLEAR_BPB_ASCII_BUFFER PROC    
;       [zeros the ascii buffer]

        xor bx,bx
        lea bx,[__BPB_ASCII_BUFFER]
        mov cx,08ah
        
        ZERO_ASCII_BUFFER:  ;  <--------------  from loop
        mov [bx],00h        ;needs a TYPE override?
        inc bx
        loop ZERO_ASCII_BUFFER
ret
ENDP
       
FIL_BPB_ASCII_BUFFER PROC    
;       [copies sector buffer into bpb ascii buffer]

        xor bx,bx       ;
        xor cx,cx
        lea bx,[__SECTOR_BUFFER]
        add bx,0bh                     ;offset to BPB
        mov si,bx
        xor bx,bx
        lea bx,[__BPB_ASCII_BUFFER]
        mov di,bx
        mov cx,08ah
        rep movsb

ret
ENDP

READ_BPB PROC

       ;Copy BPB into a variables as a block "a test"
       ;this should keep alignment with original data
       ;    should i just copy from ascii buffer?

        xor bx,bx       ;
        xor cx,cx
        lea bx,[__SECTOR_BUFFER]
        add bx,0bh                      ;offset to BPB
        mov si,bx
        xor bx,bx
        lea bx,[__BYTES_PER_SECTOR]     ;first item in variable block
        mov di,bx
        mov cx,11h
        rep movsb
ret
ENDP


CONVERT_TO_DISPLAYABLE PROC ;(seg,[bx])      "segment for data,pointer to
;                                         data to be converted"
;                                          -these are written to
;                                         before calling this function


;      [goes to each byte and converts to ascii]
        SAVE_REGISTERS                     ;register MACR0




INITIALIZE_POINTERS_CTD:
        ;DBFR_BASEPTR = __BPB_ASCII_BUFFER  "this was sent to this function in bx"


        mov DBFR_BASEPTR,bx          ;operand type mismatch?
        mov DBFR_PTR,bx

        lea bx,_HEX_TABLE
        mov HEXTBL_BASEPTR,bx        ;initial values,points to beginning of table
        mov HEXTBL_PTR,bx

        lea bx,_ASCII_TABLE
        mov ASCII_TABLE_BASEPTR,bx
        mov ASCII_TABLE_PTR,bx
        ;######################



GET_VALUE_TO_TEST_CTD:

      


LOOP_GET_VALUE_CTD:       ;<-----------------------------------------------------
        xor ax,ax
;       [THIS POINTS TO THE DISPLAY BUFFER POSITION TO CONVERT]
        mov ax,[[DBFR_PTR]]        ;match wasnt found if this loops back here,this should not change yet?
        SPLITAX                  ;setup AX so the "nibbles" can be tested

NEXT_HEX_TEST_CTD:        ;<<--------------------------------------------
;        mov ax,[DBFR_PTR]         ;setup values to compare                              
        
        mov dx,[HEXTBL_PTR]
        SPLITDX
        cmp ax,dx                 ;do the comparison
        je MATCH_CTD              ;match found,also,stays within loop structure

NO_MATCH_CTD:
        inc [HEXTBL_PTR]          ;increment hextable pointer to next value to test
        jmp NEXT_HEX_TEST_CTD     ;display buff pointer stays same,------------>>
                                  ;but hex tries another value 

MATCH_CTD:
        mov ax,HEXTBL_PTR        ;match found,copy *HEXTBL_PTR to *ASCII_TABLE_PTR
        mov ASCII_TABLE_PTR,ax   ;
        mov ax,[ASCII_TABLE_PTR] ;copy value "HERE" into display buffer position,the conversion! 
        mov [DBFR_PTR],ax        ;DONE,setup next test
                          
        mov ax,[HEXTBL_BASEPTR]  ;reset hex table pointer to beginning of table
        mov [HEXTBL_PTR],ax      ;

        inc [DBFR_PTR]           ;move DBFR pointer to next value to convert
                                 ;ASCII pointer doesnt have to be reset since it gets
                                 ;its value when a match is found.
                                 ;falls thru to "next_value...

NEXT_VALUE_CTD:
        loop LOOP_GET_VALUE_CTD ;

RESTORE_REGISTERS
ret
ENDP
;##################################################################################


    
    GET_SIZE:                     
        xor ax,ax                 
        xor bx,bx                        ;__BIOS_PARAMETER_OFFSET use this instead of 0Bh
        xor cx,cx
        lea bp,__BPB_ENTRY_SIZE          ;Get BPB item size to test
        mov cl,[bp]                      ;copies size into cl
        
       ;if 1 byte got this
        mov ch,01h
        cmp ch,cl
        je COPY_DATA_ITEM_AX
        
       ;if 2 bytes goto that
        mov ch,02h
        cmp ch,cl
        je COPY_DATA_ITEM_DX
        
        
   COPY_DATA_ITEM_DX:     
        lea bp,__BPB_ASCII_BUFFER        ;Base address 
        
        mov dl,[bp+_TABLE_OFFSET]        ;copy 1st byte into bufflow
        inc [_TABLE_OFFSET]
        mov dh,[bp+_TABLE_OFFSET]        ;copy 1st byte into buffhigh

        jmp END_COPY_DATA

   COPY_DATA_ITEM_AX:
        lea bp,__BPB_ASCII_BUFFER        ;first item in variable block 
        mov al,[bp+_TABLE_OFFSET]
    END_COPY_DATA:                                      
        
        
        
        mov al,[bp]
        inc bp
        mov bx,02h
        sub ax,bx
        
        
        lea dx,_HEX_TABLE
    
                         ;what were going to test

    


DISPLAY_BPB:
           
           
           jmp ACTIVE_PAGE

           
           

ACTIVE_PAGE:           
      
         ; get Active Display page
           xor ax,ax
           xor bx,bx
           mov ah,0fh
           int 10h
           
           
           xor ax,ax
           xor bx,bx
           mov bl,07h             ; set attribute so it will DISPLAY!
           mov ah,13h             ; sub-func 13 "write string" 
           mov al,01h             ; cursor "stays"
           lea bp,SectorsPerFat   ; text to DISPLAY
           mov cx,18              ; 18 characters
           mov dh,00              ; row 1 of 25,"top of screen"
           mov dl,00h             ; column 1,"left side of screen"
           int 10h

    DIRECT_WRITE:
           push ds
           xor ax,ax
           mov ah,0B8h
           mov al,00h
           mov ds,ax
           lea bp,__SECTORS_PER_FAT
           mov si,bp
           mov di,12h
           movsw
           pop ds
           ;END DIRECT_WRITE:



jmp EXIT_TO_DOS
           
           nop
           nop
           nop
           nop

           xor ax,ax
           xor bx,bx
           mov bl,07h               ;set attribute so it will DISPLAY!
           mov ah,13h               ; sub-func 13 "write string" 
           mov al,01h               ; cursor "stays"
           lea bp,__SECTORS_PER_FAT
           mov cx,01                ; 1 characters
           mov dh,00                ;row 1 of 25,"top of screen"
           mov dl,19                ;column 1,"left side of screen"
           int 10h

jmp EXIT_TO_DOS




;mov bx,0000h
;mov ds,bx
;mov es,bx
;mov bx,7c03h
;mov ah,ds:[bx]


xor ax,ax        
        ;goto the io.sys and msdos.sys sector and test for them,or mine actually
        ;print "this is a boot disk" to screen.,until my own stuff is written.




GET_DISK_MAP:

READ_IO_SYS:

READ_MSDOS_SYS:



jmp EXIT_TO_DOS


EXIT_TO_DOS:
mov ah,4ch
mov al,00h
int 21h

END START    


Edit by Loco: Please use code tags next time
Post 09 Jan 2008, 23:35
View user's profile Send private message Reply with quote
robertkey60



Joined: 09 Jan 2008
Posts: 6
robertkey60 09 Jan 2008, 23:39
_HEX_TABLE is th e problem,the other tables misbehave as well. i did make a version that builds the table in memory at startup and it works just fine. go figure? yeah this is masm syntax.i just started doing programming of any type,so i went and got "everything" i could find.
Post 09 Jan 2008, 23:39
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 09 Jan 2008, 23:48
ok, the problem is:
you make a mix between tree distinct executable formats.

.bin for bootsecto, org 100h (.com) and .exe are not the same thing, .bin is a flat binary format, .com is a single segment format, and exe is a multisegment format.
the amazement is, does this code compile correctlly?
Post 09 Jan 2008, 23:48
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 10 Jan 2008, 01:12
.

Does it compile at all ?

It is full of bugs Sad

0. ".model small"
1. [[]] doubling brackets
2. "ds:[bx]"
3. many messy lea's with different syntaxes
4. ";goto the io.sys and msdos.sys" - what's the point ? Laughing
5. "PROC" - IIRC unsupported by FASM compiler core
6. ".data" and ".code" - remove
7. "org" not at the begin
8. code not at the begin

You can test from DOS as .COM with org $0100 - but then also exit to DOS with INT $21/$4C00 Wink

I see no evidence of EXE in the code ... but you can use

Code:
   format binary as "COM" ; with org $0100, test from DOS
    

or
Code:
   format binary as "BIN" ; without org $0100, boot it
    

_________________
Bug Nr.: 12345

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

Status: Closed: NOT a Bug
Post 10 Jan 2008, 01:12
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 10 Jan 2008, 12:11
exe evidence is in the .code .data declarations, used mainly for exe code.
Post 10 Jan 2008, 12:11
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.