flat assembler
Message board for the users of flat assembler.

Index > Main > Problems reading IVT and saving to a buffer

Author
Thread Post new topic Reply to topic
Walkerboh



Joined: 08 Jul 2010
Posts: 17
Walkerboh 22 Jul 2010, 00:54
I'm very new to assembly, I started learning it about a month ago so I could be missing something very basic here. What I'm trying to do is read the Interrupt Vector Table and save the address for each INT to a buffer where I can view them. If possible would some1 either tell me where I'm going wrong or write me an example of how to properly go about this?

Code:
ORG 100h
USE16


      PUSH    es
  MOV     ax, 0
       MOV     es, ax
      XOR     bx, bx
      XOR     cx, cx
ReadLoop:
     ;STORE THE WORD AT es:bx into ax
        MOV     ax, word [es:bx]
        INC     bx
  INC     bx

      ;MOVE THE WORD IN ax INTO IvtReadBuffer+cx
  PUSH    bx
  MOV     bx, cx
      MOV     [IvtReadBuffer+bx], ax
      POP     bx

      ;STORE THE WORD AT es:bx into ax
        MOV     ax, word [es:bx]
        INC     bx
  INC     bx

      ;MOVE THE WORD IN ax INTO IvtReadBuffer+cx
  INC     cx      
    PUSH    bx
  MOV     bx, cx
      MOV     [IvtReadBuffer+bx], ax
      POP     bx

      ;SEE IF ALL 1024 BYTES OF IVT HAVE BEEN READ, RESTART LOOP IF NOT       
    CMP     bx, 1024
    INC     cx
  JNE     ReadLoop
    POP     es

DisplayBuffer:
        MOV     ah, 09h
     MOV     dx, IvtReadBuffer
   INT     21h

EndProgram:
  MOV     ah, 4ch
     INT     21h

IvtReadBuffer        du 512 dup (?)
TerminateString db '$'

    
Post 22 Jul 2010, 00:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 22 Jul 2010, 01:06
Maybe you need two 'inc cx', to match the two 'inc bx', for each word transferred.

Also, think about using 'rep movsw'
Post 22 Jul 2010, 01:06
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 22 Jul 2010, 01:14
hello.

about IVT, it is only a memory, no matter of the organisation when yuo transfert datas, just know the count of bytes to tranfert, and it is ok.

then:
Code:

mov ax,0
mov gs,ax
mov cx,256*4/2
mov di,0

@@:
   mov ax,[gs:di]
   mov [ivt+di],ax
   loop @b

    


that's all fo the data transfert

for the view of the ivt, it depends onwhat you say by "view".
in hexadecimal?

for this, you should create a text that represent your ivt in the form you want. after, you call the DOS int to display text, but before, you should convert the datas in plain text.
Post 22 Jul 2010, 01:14
View user's profile Send private message Visit poster's website Reply with quote
Walkerboh



Joined: 08 Jul 2010
Posts: 17
Walkerboh 22 Jul 2010, 02:09
Thank you both! This will be enough to get me going again after work tomorrow Smile I initially tried the movsw string operation but took it out when i still had problems, i thought maybe i was corrupting a register somehow. Once i get the values into a buffer I plan to convert them into a string in hexadecimal format.
Post 22 Jul 2010, 02:09
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 22 Jul 2010, 03:12
I think if just viewing them it is better to do it this way...
Please note that i have a serious buzz going and no PC to test this...
If you prove it works correctly then you can start to optimize it (for size)
Code:
org 100h
use16
        cld
        mov     ah,09h
        mov     dx,g_header
        int     21h

        xor     si,si
        mov     fs,si
        mov     cx,si

print_ivt:

        mov     dx,cx
        mov     di,g_format+2
        call    store_hex

        mov     dx,[fs:si]
        mov     di,g_format+18
        call    store_hex

        mov     dx,[fs:si+2]
        mov     di,g_format+10
        call    store_hex

        mov     ah,09h
        mov     dx,g_format
        pusha   ; paranoid
        int     21h
        popa

        add     cx,1
        add     si,4
        cmp     cx,256
        jl      print_ivt

        mov     ah,07h
        int     21h

        mov     ax,4c00h
        int     21h

store_hex:
        ; DX = value
        ; ES:DI -> dest
        pusha
        mov     cx,4
    @@: rol     dx,4
        mov     al,dl 
        and     al,0Fh 
        cmp     al,10 
        sbb     al,069h 
        das 
        stosb
        loop    @b
        popa
        ret

g_header db 'INT     CS      IP',13,10,'$'
g_format db '0x????  0x????  0x????',13,10,'$'
    

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 22 Jul 2010, 03:12
View user's profile Send private message Reply with quote
Walkerboh



Joined: 08 Jul 2010
Posts: 17
Walkerboh 22 Jul 2010, 22:17
Indeed it works! Thanks for the code to study =D
Post 22 Jul 2010, 22:17
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 23 Jul 2010, 19:44
I don't understand ..
What OS do you use for programming in 16bit code
and be able to use int_21?
you don't use windows ? maybe a DOS emulation ?
thank you

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 23 Jul 2010, 19:44
View user's profile Send private message Send e-mail Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 23 Jul 2010, 22:53
I have Win-XP2 and it lets me use DOS/BIOS interrupts.
The values returned from my proggy were not IBM-PC BIOS.
I think windows must have remapped them on me.
To really test it out you would put code in bootsector.
Assuming you replace DOS interrupts with BIOS interrupts.
Then i think it will give the correct results.
Post 23 Jul 2010, 22:53
View user's profile Send private message Reply with quote
Walkerboh



Joined: 08 Jul 2010
Posts: 17
Walkerboh 25 Jul 2010, 18:54
I'm having a little trouble understanding exactly how a portion of your code works bitshifter. In the store_hex procedure, I believe you are taking 4 bits at a time from the value in dx and converting it to its hex equivalent on the ASCII table where you then stosb the value. What's the purpose of
CMP al,10
SBB al,069h
DAS
The best I can guess is you're using CMP to set CF, but why are you subtracting 069h+CF from al..wouldn't that always be a negative number since the max value of 4 bits is 15?

store_hex procedure:
Code:
@@: rol     dx,4
        mov     al,dl 
        and     al,0Fh 
        cmp     al,10 
        sbb     al,069h 
        das 
        stosb
        loop    @b 

    
Post 25 Jul 2010, 18:54
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1403
Location: Piraeus, Greece
Picnic 25 Jul 2010, 19:05
This might clear things up for you Wink

Code:
cmp al, 10          ; Sets the carry flag if it's a digit.
                    ; Remember, JB (Below) = JC (Carry).
            
sbb al, 69h         ; subtract 70 (BCD) for digits
                    ; subtract 69 (BCD) for letters
            
das                 ; BCD fix for subtraction:
                    ; (1)00..(1)09 - 70 = 30..39 = '0'..'9'
                    ; (1)10..(1)15 - 69 = 41..46 = 'A'..'F'
    
Post 25 Jul 2010, 19:05
View user's profile Send private message Visit poster's website Reply with quote
Walkerboh



Joined: 08 Jul 2010
Posts: 17
Walkerboh 26 Jul 2010, 00:55
It sure did, thanks Smile
Post 26 Jul 2010, 00:55
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.