Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Write data into text file

$
0
0
Hi. I have to write simple program in assembly (using tasm for compiling) which will add to numbers and save their sum into text file. I have managed to do first part, but when trying to save sum into file it won't work (operand doesn't match). Dunno what i'm doing wrong. Can someone help me or rewrite code to show me, how it should be done?
.model small
.stack 200H
.data
   msg1 DB 10,13,'Enter the first no: $'
   msg2 DB 10,13,'Enter the second no: $'
   msg3 DB 10,13,'sum = $'
   newline DB 10,13, ' $'
   file DB "C:\tasm\results.txt",00
.code
   print MACRO msg ;macro definition
   PUSH AX
   PUSH DX
   MOV AH,09H
   MOV DX,offset msg
   INT 21H
   POP DX
   POP AX
   ENDM
.startup
   print msg1
   CALL readnumtoAX
   MOV CX,AX
   print newline
   print msg2
   CALL readnumtoAX
   print newline
   print msg3
   ADD ax,cX
   CALL displayAX
   CALL saveAX
.exit
readnumtoAX PROC NEAR
   PUSH BX
   PUSH CX
   MOV CX,10
   MOV BX,00
back:
   MOV AH,01H
   INT 21H
   CMP AL,'0'
   JB skip
   CMP AL,'9'
   JA skip
   SUB AL,'0'
   PUSH AX
   MOV AX,BX
   MUL CX
   MOV BX,AX
   POP AX
   MOV AH,00
   ADD BX,AX
   JMP back
skip:
   MOV AX,BX
   POP CX
   POP BX
   RET
readnumtoAX ENDP
displayAX PROC NEAR
   PUSH DX
   PUSH CX
   PUSH BX
   PUSH AX
   MOV CX,0
   MOV BX,10
back1:
   MOV DX,0
   DIV BX
   PUSH DX
   INC CX
   OR AX,AX
   JNZ back1
back2:
   POP DX
   ADD DL,30H
   MOV AH,02H
   INT 21H
   LOOP back2
   POP AX
   POP BX
   POP CX
   POP DX
   RET
  displayAX ENDP
  saveAX PROC
	MOV AH,3D
	MOV AL,20
	MOV DX,file
	INT 21h
	MOV BX,AX
	MOV AX,4000
	MOV DX,cX
	MOV CX,0D
	INT 21H
	MOV AX,4c00
	INT 21H
	saveAX ENDP
end

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>