如何使用TASM写入txt文件

时间:2017-04-04 22:31:26

标签: assembly tasm dosbox

因此,打开文件和关闭文件工作得很好,它可以像读取文件那样工作, 现在,我试图通过解除数字并将它们转换为ascii代码来更新txt文件中的数字,在我这样做之后,将它们用于编写,似乎在我的txt文件中没有编辑任何内容,发生了什么?

coins db 31
coinsArray db 3 dup (0)
coinsLeng dw ?
buffer db 256 dup (0)

proc WriteToFileCoins
    push ax
    push bx
    push cx
    push dx
    mov ah, 40h
    mov bx, [fileHandle]
    call SetCoinsInBuffer ;Setting the numbers to appear in the buffer
    mov cx, [coinsLeng] ;Length to be used
    inc cx ;Since the length is counted 0 && 1 but interrupt reads till 0
    mov dx, offset buffer
    int 21h
    call CloseFile
    pop dx
    pop cx
    pop bx
    pop ax
    ret
endp WriteToFileCoins

proc SetCoinsInBuffer
push ax
push di
push bx
push cx
push si
    xor ax, ax
    mov di, 0
    mov bl, 10d
    mov al, [coins]
ASC2:
        xor ah, ah
        div bl             ; ax/bl
        mov ch, ah         ; Asci number starts at 48, saving and adding.
        add ch, 48d
        mov [coinsArray+di], ch           ; Saves in array
        cmp al, 0d
        je CoinsSet             ;IF AX=0, END OF THE PROCEDURE
        inc di
        jmp asc2
CoinsSet:
    mov [coinsLeng], di ; I saved them reversed in the 'coinarray'
    xor si, si
CoinsReSet:
    xor bx, bx
    mov bl, [coinsArray+di]
    mov [buffer+si], bl
    cmp di, 0
    je FinishedSettingBuffer
    dec di
    inc si
    jmp CoinsReSet
FinishedSettingBuffer:
pop si
pop cx
pop bx
pop di
pop ax
ret
EndP SetCoinsInBuffer

0 个答案:

没有答案