how to write assembly language to make DMA works

Viewed 945

I know there are 3 ways to transmit the IO data: program mode,interrupt mode and DMA mode. And for the program mode, if I want to transmit a byte from IO to RAM, I should write like this

MOV PORT1,000AH        # tell io the address
IN ACC,PORT2           # read data from this address
MOV [0x5566], ACC      # mov this data to RAM

And if I want to transmit many bytes, I foreach this program. That's OK. But here is my question:

What if I want to use DMA mode,how to write my assembly language to transmit many bytes from IO to RAM?

I know how DMA works, but I am confused about who tells them to do this?I think cpu need to tell the IO start address, the data length, the RAM address. All of this, what the assembly language should be?

I found a lot but didn't find answer. Did I miss something important that make I confused about this? I hope someone's help.Thanks

1 Answers

There is a book with the very long title:

"THE INTEL MICROPROCESSORS 8086/8088, 80186/80188, 80286, 80386, 80486, Pentium, Pentium Pro Processor, Pentium II, Pentium III, Pentium 4, and Core2 with 64-Bit Extensions Architecture, Programming, and Interfacing Eighth Edition BARRY B. BREY"

the example from the book:

;A procedure that transfers a block of data using the 8237A
;DMA controller in Figure 13–12. This is a memory-to-memory
;transfer.
;Calling parameters:
; SI = source address
; DI = destination address
; CX = count
; ES = segment of source and destination
LATCHB EQU 10H
CLEARF EQU 7CH
CHOA EQU 70H
CH1A EQU 72H
CH1C EQU 73H
MODE EQU 7BH
CMMD EQU 78H
MASKS EQU 7FH
REQ EQU 79H
STATUS EQU 78H
TRANS PROC NEAR USES AX
MOV AX,ES                ;program latch B
MOV AL,AH
SHR AL,4
OUT LATCHB,AL
OUT CLEARF,AL             ;clear F/L
MOV AX,ES                 ;program source address
SHL AX,4
ADD AX,SI
OUT CH0A,AL
MOV AL,AH
OUT CH0A
MOV AX,ES                 ;program destination address
SHL AX,4
ADD AX,DI
OUT CH1A,AL
MOV AL,AH
OUT CH1A,AL
MOV AX,CX                   ;program count
DEC AX
OUT CH1C,AL
MOV AL,AH
OUT CH1C,AL
MOV AL,88H              ;program mode
OUT MODE,AL
MOV AL,85H
OUT MODE,AL
MOV AL,1            ;enable block transfer
OUT CMMD,AL
MOV AL,0EH             ;unmask channel 0
OUT MASKS,AL
MOV AL,4                 ;start DMA
OUT REQ,AL
.REPEAT               ;wait for completion
IN AL,STATUS
.UNTIL AL & 1
RET
TRANS ENDP

Also, exactly the same piece of code can be found here

Related