Assembly Code Share

Moderators: None (Apply to moderate this forum)
Number of threads: 375
Number of posts: 685

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Problem writing to .txt Posted by jdcb92 on 28 Mar 2012 at 10:04 PM
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.

TAREA SEGMENT STACK
	DW 128 DUP (?)
TAREA ENDS

DATA SEGMENT
	SALUDO    DB  "Inserte el texto:",13,10, "$" ;Means insert text:
	ARCHIVO   DB  "C:\tasm\bin\ArchivoSalida.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


Here are some examples of what it writes into txt

abcde=Luÿ(and 2 more things that didn't appar when I pasted)
abcdefghi=LuÿÃ V(and more things that aren't copied when pasted)

The real issue here is...how do I specify the function to use Ascii to write into file? Or what else can I do?

Thanks in advance. I'm using W7 and TASM.



Report
Re: Problem writing to .txt Posted by sergioavendano on 29 Mar 2012 at 10:24 AM
And tried to make your comparisons in Hex? for example instead of:

NOVENTAYSEIS:
CMP AL, 96
JA ESCRITURA
JB NOVENTA

Try:

NOVENTAYSEIS:
CMP AL, 60h
JA ESCRITURA
JB NOVENTA

Greetings !!
Report
Re: Problem writing to .txt Posted by sergioavendano on 29 Mar 2012 at 10:27 AM
And tried to make your comparisons in Hex? for example instead of:

NOVENTAYSEIS:
CMP AL, 96
JA ESCRITURA
JB NOVENTA

Try:

NOVENTAYSEIS:
CMP AL, 60h
JA ESCRITURA
JB NOVENTA

Greetings !!
Report
Re: Problem writing to .txt Posted by sergioavendano on 29 Mar 2012 at 10:30 AM
And tried to make your comparisons in Hex? for example instead of:

NOVENTAYSEIS:
CMP AL, 96
JA ESCRITURA
JB NOVENTA

Try:

NOVENTAYSEIS:
CMP AL, 60h
JA ESCRITURA
JB NOVENTA

Greetings !!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.