Hi all,
I want to learn about how I can print out an integer in MASM. As code below;
PAGE 60,132
.MODEL SMALL
.STACK 64
.DATA
MES DB "ENTER A NUM: ","$"
INP DB 30,?,30 DUP("$")
ENTER DB 13,10,"$"
SUM DB ?
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX
MOV CL,0
SUB BL,BL
MOV CH,00DDh
FOR1:
MOV AH,9
MOV DX,OFFSET MES
INT 21H
MOV AH,10
MOV DX,OFFSET INP
INT 21H
MOV AH,9
MOV DI,OFFSET INP
INC DI
INC DI
MOV BX,[DI]
SUB BL,30H
MOV DX,OFFSET ENTER
INT 21H
CMP BL,CH
JE EXIT
SUB DL,DL ;CLEAN DL
ADD DL,BL
DAA
ADD SUM,DL
MOV AX,SUM
Puti
MOV BX,4
INC CL
CMP CL,BL
JNE FOR1
WRITE:
;Print code here??
EXIT:
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
What is the solution for that WRITE label?? I do not know if it is easy or not but I just wanted to ask. Thanks for your patience...
Hi ilkeronurkaya,
is this homework or an assignment? In any case, i am moving it to the 16 bit forum as that is a more appropriate place for it. You will need to access an interrupt to get your number on the screen, the 16 bit guys will be able to help you.
it a part of my homework but my goal is not to complete it. it is also comlepeted but printing out the sum to the screen. i have coded all part of my homework but WRITE label... Thank you for your help...
Hi ilkeronurkaya,
Your code will not assemble. You need to get it to assemble before you can solve any other problems.
ilk.asm(7) : error A2085: instruction or register not accepted in current CPU mode
line 7: ENTER DB 13,10,"$"
ilk.asm(30) : error A2085: instruction or register not accepted in current CPU mode
line 30: MOV DX,OFFSET ENTER
ENTER is an instruction mnemonic so you cannot use it as a label. Try CRLF instead (CRLF is a common abbreviation for Carriage Return, Line Feed).
ilk.asm(38) : error A2070: invalid instruction operands
line 38: MOV AX,SUM
SUM is defined as a byte, and you are trying to move it into a word register.
ilk.asm(39) : error A2008: syntax error : Puti
Is Puti supposed to be a label, a comment, or what?
Beyond that I cannot determine from your code what you are trying to do.
The code inputs 4 numbers. Are these supposed to be single-digit numbers?
If you are storing the sum in a byte then it cannot exceed 255.
DAA adjusts an 8-bit binary value in AL to a packed BCD. The code does not store anything in AL ahead of the DAA, and the code overwrites the value in AL after the DAA.
What is the purpose of the value DDh that is being loaded into CH and later compared to the value in BL?
To display the sum on the screen you will first need to convert it to decimal digits. Instead of code, I will provide a description:
One simple, easy to understand method would be to extract the digit values in reverse order by taking the remainder when the number is divided by ten, continuing until the quotient is zero.
For example:
123 / 10 = 12 remainder 3
12 / 10 = 1 remainder 2
1 / 10 = 0 remainder 1
Then starting with the last value extracted, you would convert each digit value to a character code by adding the character code value for "0" and either display each character or add it to a string. The stack provides a convenient method of reversing the order of the digit values.
Merhaba Ilker,
NasılsIn? :) Foruma hosgeldin.
Welcome on board.
MichaelW posted a routine to print 16-bit integer numbers, here is an example application using MichaelW's PrintDec algo.
[attachment deleted by admin]