Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problem writing to .txt

Hi! I'm making a little program that receives characters from keyboard and from those characters only the letters received will be writen into a .txt file, but I'm having trouble writing. The code writes into the file but the things written are very weird, are not in the ASCII table and sometimes they are completely different.

Here's the code:
It's originally writen in spanish but I'll translate some things with comments.

[code]TAREA SEGMENT STACK
DW 128 DUP (?)
TAREA ENDS

DATA SEGMENT
SALUDO DB "Inserte el texto:",13,10, "$" ;Means insert text:
ARCHIVO DB "C: asminArchivoSalida.txt", 00h
CONTADOR DB 0
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:TAREA

INICIO:
MOV AX, DATA
MOV DS, AX
MOV DX, OFFSET SALUDO
MOV AH, 09h
INT 21h

ABRE:
MOV AH, 3Ch ;loads create file instruction
MOV CX, 00
LEA DX, ARCHIVO
INT 21h ;calls interruption
MOV BX, AX ;moves handle to BX

PRIMERALLAMADA: ;first call
MOV AH, 01h ;loads instruction to receive from keyboard
INT 21h ;calls interruption
CMP AL, 13 ;compares if user pressed enter
JZ CICLO_TECLADO ;calls the cycle that keeps receiving from keyboard

CIENTOVEINTIDOS: ;compares if letter
CMP AL, 122
JA CICLO_TECLADO ;jumps to cycle if bigger than 122 in Ascii
JB NOVENTAYSEIS ;if smaller than 122 keeps going

NOVENTAYSEIS: ;compares if letter
CMP AL, 96
JA ESCRITURA ;if bigger than 96 means its a letter in Ascii
JB NOVENTA ;keeps comparing if smaller

NOVENTA: ;compares if letter
CMP AL, 90
JA CICLO_TECLADO
JB SESENTAYCUATRO

SESENTAYCUATRO:
CMP AL, 64
JA ESCRITURA
JB CICLO_TECLADO

ESCRITURA: ;tag that writes into file
MOV AH, 40h ;load write to file instruction
MOV CX, 1 ;amount of bytes to write
MOV DH, AL ;data to be written
int 21H ;interruption
JMP CICLO_TECLADO ;calls loop to receive from keyboard

CICLO_TECLADO:
MOV AH, 01h ;calls instruction to receive from keyboard
INT 21H ;calls interruption
CMP AL, 13 ;compares if enter
JNZ CIENTOVEINTIDOS ;starts comparison if letter

TERMINA: ;end
MOV AH, 3Eh ;closes file
Int 21h
MOV AH, 04Ch ;finishes program
INT 21h

CODE ENDS
END INICIO
END ABRE
END PRIMERALLAMADA
END CIENTOVEINTIDOS
END NOVENTAYSEIS
END NOVENTA
END SESENTAYCUATRO
END ESCRITURA
END CICLO_TECLADO
END TERMINA[/code]

Here are some examples of what it writes into txt

abcde=Lu

Comments

Sign In or Register to comment.