I am writing the code for the following program,
Objective:
Count the number of spaces pressed by the user. Break if enter is pressed.
Code:
.MODEL SMALL
.STACK 100H
.DATA
TEXT DB "Enter Character"
.CODE
MOV AX,9
MOV DX,TEXT
INT 21H
BACK:
INT21H
CMP AL, " "
JE INCREMENT
CMP AL, "\n"
JE OUT
JMP BACK
INCREMENT:
INC ; which register do I use here? I feel that I am out of registers
LOOP BACK
OUT:
;display the count
In the above code, I have marked the area where I am feeling that I don’t have anymore registers left to use. I have to use AX,AL,DX,DL registers in the code. Which other register can I use to store the count? Please help, thanks.
You have the following general-purpose registers that you can use:
AX(AHis 8 most significant bits ofAX,ALis 8 least significant bits ofAX)BX(BHis 8 MSBs ofBX,BLis 8 LSBs ofBX)CX(CHis 8 MSBs ofCX,CLis 8 LSBs ofCX)DX(DHis 8 MSBs ofDX,DLis 8 LSBs ofDX)BP(individual halves aren’t accessible directly)SI(individual halves aren’t accessible directly)DI(individual halves aren’t accessible directly)Btw, you have to set
AHto 1 beforeint 21Hthat reads a character intoALfrom the keyboard.And your text string must end with a dollar sign if you want to print it using
int 21Hfunction 9.Also, Enter’s code is 13 (‘\r’), not 10 (‘\n’).
A few more issues:
DSto point to the data segment. See your book or notes or assembler documentation on how to do that.ESshould probably be set to the same value.