Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read IO or Memory in DOS

Status
Not open for further replies.

dinhtandl

Programmer
Oct 24, 2010
1
0
0
VN
Dear all,

I use MASM611 to compile code assemply.
Please hepl me to implement functions to read IO or Memory.
I have a Base Address (example: 0xE1004000), i want to read IO or Memory at this address. And is this address a IO Addrress or Memory Address in DOS?
And Following code is code to read IO at the address is lower 0xFFFF:

; _ioread
;
; This procedure reads data from the io port specified. Data can
; be a byte, word or long word as specified by the size parameter.
;
; C Prototype
;
; Note: The maximum address is 0xFFFF
; short ioread(unsigned long addr, unsigned long * data, short size);
;
; addr - io address to write to
; data - location where data will be stored.
; size - size of data to read in bytes. {1, 2, 4}
;
_ioread PROC FAR
push bp
mov bp,sp

push ebx ; save registers
push edx
push di
push es

; get io address and check to make sure it's in range
mov edx,[bp+6] ; address
cmp edx,0000FFFFH
jg ioread_err_range

xor eax,eax ; prepare to recieve data
mov bx,[bp+0EH] ; size

cmp bx,4 ; write long word
jne ioread_check_word
in eax,dx
jmp ioread_err_ok

ioread_check_word: ; write word
cmp bx,2
jne ioread_check_byte
in ax,dx
jmp ioread_err_ok

ioread_check_byte: ; write byte
cmp bx,1
jne ioread_err_range
in al,dx
jmp ioread_err_ok

ioread_err_ok: ; successful procedure
mov edx,[bp+0AH] ; data
mov di,dx
shr edx,16
mov es,dx
mov es:[di],eax ; store result
xor ax,ax
jmp ioread_omega

ioread_err_range: ; range error in procedure
mov ax,0FFFFH

ioread_omega:

pop es ; restore registers
pop di
pop edx
pop ebx

mov sp,bp
pop bp
ret
_ioread ENDP

I want to edit this code to read with 32 bit address.
Please help me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top