flat assembler
Message board for the users of flat assembler.

Index > OS Construction > specific data transfer

Author
Thread Post new topic Reply to topic
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
im trying to get the 3rd byte in my buffer, it is a string 8 bytes long and im trying to move it into anotehr register

ive tried
note si, contains the buffer and ax it where im trying to get the string into
ive tried

mov byte ax, [si+3] (then plus 4 thern 5 all the way up to 11)
but it wouldnt work, could some one give me a techinique on takeing a specific byte in a buffer and putting it in a register

_________________
Oh that divide overflow. Just jumps out of the bushes every time to scare the day lights out of me.
Post 01 Jan 2010, 00:36
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
mmm, maybe this:
Code:
mov al, [si+3]
; Or perhaps this below?
movzx ax, byte [si+3] ; AL = [SI+3]; AH = 0    


That is accessing fourth character/byte actually, [si+0] (i.e. [si]) access the first char/byte.

In case that 3rd byte is just an example, you can use a second register to hold the index, for instance suppose that BX is the pointer to the buffer and DI the index (equal to two), then it would be this:
Code:
mov al, [bx+di]    
Post 01 Jan 2010, 01:00
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
thanks for the fast response Smile

_________________
Oh that divide overflow. Just jumps out of the bushes every time to scare the day lights out of me.
Post 01 Jan 2010, 01:19
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
should i inc al before i add more?


mov al, [si+3]
inc al
mov al, [si+4]

_________________
Oh that divide overflow. Just jumps out of the bushes every time to scare the day lights out of me.
Post 01 Jan 2010, 01:38
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
Quote:
mov byte ax, [si+3] (then plus 4 thern 5 all the way up to 11)


IS THIS WHAT YOUR DOING? Shocked
Code:
mov byte ax, [si+3]
mov byte ax, [si+4]
mov byte ax, [si+5]
mov byte ax, [si+6]
    


if so you are overwriting ax each time... Wink

if you want the all 8 bytes you could do this:
Code:
buffer db "abcdefghijklmnop",0

mov si,buffer
mov di,my_8_bytes

mov ax, [si+3] ;get 2 bytes
mov [di+0],ax  ;store ax
mov ax, [si+5] ;get 2 bytes
mov [di+2],ax  ;store ax
mov ax, [si+7] ;get 2 bytes
mov [di+4],ax  ;store ax
mov ax, [si+9] ;get 2 bytes
mov [di+6],ax  ;store ax
;once here my_8_bytes is loaded with the string defghijk
my_8_bytes: times 9 db 0 ; empty space to store the 8 bytes..

    

above is the hard way..to much code.. but for 8 bytes not to bad

better to use a loop or something ..

and if you just want a byte at a time use al..

mov al, [si+3] ;
mov [di+0],al
mov al, [si+4]
mov [di+1],al


Quote:
inc al

no = this would just take the value in al and add 1


Last edited by dosin on 02 Jan 2010, 00:44; edited 1 time in total
Post 01 Jan 2010, 09:38
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
i may not of learned my lesson, but i am trying to get infommation fromt he bootloader to the disk

with si containing my buffer

mov [bpbBytesPerSector],[si+10]
mov [bpbBytesPerSector],[si+11]

it wont work, how can i acheive puting the contents, two bytes, from the 10th and 11th byte in si into bpbBytesPerSector variable

_________________
Oh that divide overflow. Just jumps out of the bushes every time to scare the day lights out of me.
Post 01 Jan 2010, 23:28
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
Quote:

mov [bpbBytesPerSector],[si+10]
mov [bpbBytesPerSector],[si+11]


Code:
bpbBytesPerSector: dw 0
;get one value at a time store in al and save each one
mov al,byte[si+10]
mov byte[bpbBytesPerSector+0],al

mov al,byte[si+11]
mov byte[bpbBytesPerSector+1],al

;or move 2 bytes/1 word at once.. 10 and 11 into ax and save them
mov ax,word[si+10]
mov word[bpbBytesPerSector],ax
    


you should read up on the registers and fasm manual - it will help.. Wink
but this should give you some idea..
Post 02 Jan 2010, 00:30
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
thank u for the suggestion, i have read the manual a couple times, but maybe not throrough enough, but i will. thank u for your time
Post 02 Jan 2010, 01:15
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
np - it can be confusing.. but if you need help just post..
I have to look stuff up all the time.. Laughing
Post 02 Jan 2010, 01:20
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
Code:
checkdiskinformation:
pusha
mov ah, 02h
mov al, 1 ;just the bootloader 
mov ch, 0 
mov cl, 1 
mov dh, 0 
mov dl, 00h 
push cs 
pop es 
mov bx, databuf 
int 13h
;;databuf Contains the bootloader for data manipulation
mov si, databuf
;;get bytes per sector
mov ax,word[si+10]
mov word [bpbBytesPerSector+0], ax
;get sectors per cluster
mov ax,ax
mov al, byte[si+12]
mov byte [bpbSectorsPerCluster+0], al
;get reserved sectors
mov al,al
mov ax, word[si+13]
mov word [bpbReservedSectors], ax
;get number of fats (lol fats)
mov ax,ax
mov al, byte [si+15]
mov byte [bpbNumberOfFATs], al
;get number of root entries
mov al,al
mov ax, word [si+16]
mov word [bpbRootEntries], ax
;get total sector count
mov ax,ax
mov ax, word [si+18]
mov word [bpbTotalSectors], ax
;get sectors per fat
mov ax,ax
mov ax, word [si+21]
mov word [bpbSectorsPerFAT], ax
;get sectors per track
mov ax,ax
mov ax, word [si+23]
mov word [bpbSectorsPerTrack], ax
;get numbers of head per cylinder
mov ax,ax
mov ax, word [si+25]
mov word [bpbHeadsPerCylinder], ax
;get bootsignature
mov ax,ax
mov al, byte [si+37]
mov byte [bsExtBootSignature], al
;get volume id
mov al,al
mov al, byte [si+42]
mov byte [bsVolumeLabel+0],al
mov al,al
mov al, byte [si+43]
mov byte [bsVolumeLabel+1],al
mov al,al
mov al, byte [si+44]
mov byte [bsVolumeLabel+2],al
mov al,al
mov al, byte [si+45]
mov byte [bsVolumeLabel+3],al
mov al,al
mov al, byte [si+46]
mov byte [bsVolumeLabel+4],al
mov al,al
mov al, byte [si+47]
mov byte [bsVolumeLabel+5],al
mov al,al
mov al, byte [si+48]
mov byte [bsVolumeLabel+6],al
mov al,al
mov al, byte [si+49]
mov byte [bsVolumeLabel+7],al
mov al,al
mov al, byte [si+50]
mov byte [bsVolumeLabel+8],al
mov al,al
mov al, byte [si+51]
mov byte [bsVolumeLabel+9],al
mov al,al
mov al, byte [si+52]
mov byte [bsVolumeLabel+10],al
;get file system type
mov al,al
mov al, byte [si+53]
mov byte [bsFileSystem+0], al     ;-8
mov al,al
mov al, byte [si+54]
mov byte [bsFileSystem+1], al
mov al,al
mov al, byte [si+55]
mov byte [bsFileSystem+2], al
mov al,al
mov al, byte [si+56]
mov byte [bsFileSystem+3], al
mov al,al
mov al, byte [si+57]
mov byte [bsFileSystem+4], al
mov al,al
mov al, byte [si+58]
mov byte [bsFileSystem+5], al
mov al,al
mov al, byte [si+59]
mov byte [bsFileSystem+6], al
mov al,al
mov al, byte [si+60]
mov byte [bsFileSystem+7], al
popa
ret
;;data block that is filled when the disk is checked
bpbBytesPerSector:      DW 0
bpbSectorsPerCluster:   DB 0
bpbReservedSectors:     DW 0
bpbNumberOfFATs:            DB 0
bpbRootEntries:             DW 0
bpbTotalSectors:            DW 0
bpbMedia:                   DB 0xF0
bpbSectorsPerFAT:           DW 0
bpbSectorsPerTrack:     DW 0
bpbHeadsPerCylinder:    DW 0
bpbHiddenSectors:           DD 0
bpbTotalSectorsBig:     DD 0
bsDriveNumber:          DB 0
bsUnused:                   DB 0
bsExtBootSignature:     DB 0x29
bsSerialNumber:         DD 0
bsVolumeLabel:          DB 0
bsFileSystem:           DB 0
databuf: times 512 db 0 
    


it compiles well, but will it give me the information i need Wink
and its universal so if anyone wants to check the disk and gather its information before they do a disk operation, heres your chance for source, lucky knowing my os is closed source

[edit by Loco]Added code tags.
Post 02 Jan 2010, 04:57
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Code:
struc DiskInfo ; Based on http://en.wikipedia.org/wiki/File_Allocation_Table#Boot_Sector
{
  .jmp                  rb 3
  .OemName              rb 8
  .bpbBytesPerSector    dw ?
  .bpbSectorsPerCluster db ?
  .bpbReservedSectors   dw ?
  .bpbNumberOfFATs      db ?
  .bpbRootEntries       dw ?
  .bpbTotalSectors      dw ?
  .bpbMedia             db ?
  .bpbSectorsPerFAT     dw ?
  .bpbSectorsPerTrack   dw ?
  .bpbHeadsPerCylinder  dw ?
  .bpbHiddenSectors     dd ?
  .bpbTotalSectorsBig   dd ?

; Finish the structure yourself, here you should continue with the Extended BIOS Parameter Block

}
virtual at 0
  DiskInfo DiskInfo ; This is to make the structure available to compute offsets like "[SI+DiskInfo.bpbMedia]"
end virtual

checkdiskinformation:
pusha
mov ah, 02h
mov al, 1 ;just the bootloader 
mov ch, 0 
mov cl, 1 
mov dh, 0 
mov dl, 00h 
push cs 
pop es 
mov bx, databuf 
int 13h

;;databuf Contains the bootloader for data manipulation
mov si, databuf

; Now as an example I'll just compute the number of bytes (assuming media with less than 65536 sectors)

; It is assumed that DS=CS here, if not add the necessary code.
mov ax, [si+DiskInfo.bpbTotalSectors] ; cmp ax, [si+19]
mov dx, [si+DiskInfo.bpbBytesPerSector]
mul dx
mov word [bytes], ax
mov word [bytes+2], dx

; Done, without having to copy anything

popa
ret

bytes dd ?
databuf: times 512 db 0    


Note that your code has some offsets (maybe all) wrong since bpbBytesPerSector is at [SI+11]. Also it would be possible to use virtual like this
Code:
virtual at si
  info DiskInfo
end virtual    
So you can use the structure just like "mov ax, [info.bpbTotalSectors]" (remember to have SI loaded with a pointer to a buffer containing such structure first), but I think that it will be better for you to start with the method above to avoid some scope issues.

[edit]If databuf is not just an example (i.e. you always know its location at compile time), then this would be just enough:
Code:
struc DiskInfo ; Based on http://en.wikipedia.org/wiki/File_Allocation_Table#Boot_Sector
{
  .jmp                  rb 3
  .OemName              rb 8
  .bpbBytesPerSector    dw ?
  .bpbSectorsPerCluster db ?
  .bpbReservedSectors   dw ?
  .bpbNumberOfFATs      db ?
  .bpbRootEntries       dw ?
  .bpbTotalSectors      dw ?
  .bpbMedia             db ?
  .bpbSectorsPerFAT     dw ?
  .bpbSectorsPerTrack   dw ?
  .bpbHeadsPerCylinder  dw ?
  .bpbHiddenSectors     dd ?
  .bpbTotalSectorsBig   dd ?

; Finish the structure yourself, here you should continue with the Extended BIOS Parameter Block

  rb 512 - $ + .jmp ; To make the structure 512 bytes in size
}

checkdiskinformation:
pusha
mov ah, 02h
mov al, 1 ;just the bootloader 
mov ch, 0 
mov cl, 1 
mov dh, 0 
mov dl, 00h 
push cs 
pop es 
mov bx, databuf 
int 13h

; Now as an example I'll just compute the number of bytes (assuming media with less than 65536 sectors)

; It is assumed that DS=CS here, if not add the necessary code.
mov ax, [databuf.bpbTotalSectors]
mov dx, [databuf.bpbBytesPerSector]
mul dx
mov word [bytes], ax
mov word [bytes+2], dx

; Done, without having to copy anything

popa
ret

bytes dd ?
databuf DiskInfo
;store byte 0 at $-1 ; Uncomment this line if you needed databuf to be physically stored with zeroes instead of just reserve the address space    
[/edit]

[edit2]Changed "cmp ax, [databuf.bpbTotalSectors]" with "mov ax, [databuf.bpbTotalSectors]".[/edit2]


Last edited by LocoDelAssembly on 03 Jan 2010, 00:39; edited 1 time in total
Post 02 Jan 2010, 06:34
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
i have heard of the struct idea. it seems much easier then my dumb plan lol
thank u

_________________
Oh that divide overflow. Just jumps out of the bushes every time to scare the day lights out of me.
Post 02 Jan 2010, 07:53
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Just a note about my edit, you may actually still want to use the other code even if the location of databuf is fixed because the encoding of the instructions tend to be shorter when using register+displacement (when displacement is in the [-128..127] range) than when using the full address (unless setting up a registers ends up to be more expensive than the bytes saved by the shorter encoding of the probably too few references to the data structure).

If you don't understand what I've said above just ignore, I don't think you should really care about that much Razz
Post 02 Jan 2010, 08:17
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
actually all of this code coming from a very experienced fasm programmer, this is just my chance to learn things i could use even more in the future to help make even better things. and even if i dont understand it, its another reason to look into the manual and learn more about things that wud be worth learning. thank u for all of this

_________________
Oh that divide overflow. Just jumps out of the bushes every time to scare the day lights out of me.
Post 02 Jan 2010, 09:41
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
just curious, but what is in ax that u are comparing it with the variable?
Post 03 Jan 2010, 00:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17275
Location: In your JS exploiting you and your system
revolution
I expect it should be this:
Code:
mov ax, [databuf.bpbTotalSectors]    
Post 03 Jan 2010, 00:29
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: 4633
Location: Argentina
LocoDelAssembly
Yep, sorry, I was about to do "cmp [databuf.bpbTotalSectors], 0" to be able to handle larger media but then I've decided that it would be an unnecessary complexity for a simple example so I've just moved to AX to start the calculation but forgot to change the mnemonic...

I'll edit to avoid confusion.
Post 03 Jan 2010, 00:37
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp
its no problem. thank u anyway, i have to go read up on virtual, ive never had to use it.
Post 03 Jan 2010, 00:46
View user's profile Send private message 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.

Powered by rwasa.