hi guys i use tasm and I want to have an assembly program that gets user input and the program will provide the output. My desired program is when a user inputs 3 it will output asterisks just like this

input: 3
output: *
**
***

i found this code on web but it has got code errors.

.model small
data segment

    num db "ENTER A NUMBER : $"
    line db 10,13


.code
start:  

mov ax,@data
mov ds,ax

lea dx,num
mov ah,09h
int 21h 
    
call scan_num
push cx 

mov ah, 02

cmp cl, 0
je exit

mov dl,10  
int 21h     
mov dl, 13  
int 21h      

mov dl, 2Ah 
mov bl, 01  
mov bh, 02 
push bx     

initial:
int 21h  
cmp bl,cl
je exit  
inc bl  
cmp bl,bh   
jne initial   


pop bx     
push dx    

mov dl,10 
int 21h     
mov dl, 13  
int 21h     

add bh, 1   

pop dx      
push bx     

jmp initial      

exit: 
int 20h
ends 

DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS


end start

Recommended Answers

All 15 Replies

>>i found this code on web but it has got code errors.
That often happens when you try to plagiarize other people's code.

im just trying if it works, im not in the first place claiming it's me who made this.

what error message(s) does your assembler give you?

If that is all the code you found,then it is incomplete.. Where is scan_num? It calls it, but it is not in the code posted

Do you need to accept (and print) an unlimited number of asterisks?
I would imagine something less than 10 would work for the exercise, right?

Start with something like this where you ask the user for input (the number) and store it:

; Compiled with A86 (http://eji.com/a86/)
        mov ah, 09h
        mov dx, askAmount;
        int 21h                      ; Ask for amount
        mov si, storeAmount          ; Place to store the user name

;...

        int 20h                      ; *** DROP TO DOS ***
askAmount:   db 'Enter the number of asterisks [1-9] to print (CR to quit): $'
storeAmount: db '$'
storeCRLF:   db 0ah, 0dh
terminator:  db '$'
asterisks:   db '*********'
finalStop:   db 0ah, 0dh, '$'

Afterward (or in between), you can check the input value to make sure it fits between 1 and 9

getVal:
        mov ah, 01h
        int 21h                      ; Get input with echo
checkVal:        
        cmp al, 0dh                  ; 
        jz quit                      ; Quit if Carriage-return
        cmp al, 31h
        jl quit                      ; Quit if too low
        cmp al, 39h
        jg quit                      ; Quit if too high

;...

quit:
        int 20h                      ; *** DROP TO DOS ***

Once you get that part, the other part (that happens before the end) will start printing asterisks based on the input number:

keepVal:        
        mov [si], al                 ; Put entered char in storeAmount
printCrLf:
        mov dx, storeCRLF            ; print CR/LF
        call doPrint
printQuit:
        xor cx, cx
        mov cl, byte ptr[storeAmount];
        sub cl, 30h                  ; result (in CX) = num lines and stars
b4Stars:
        mov dx, finalStop            ; set pointer to NO asterisks
stars:        
        dec dx                       ; move back num to print per loop
        call doPrint
outer:
        loop stars                   ; loop til CX=0
        jmp quit
doPrint:
        mov ah, 09h
        int 21h
        ret

The whole thing can be just 44 lines of code compiled down to 138 bytes.

include 'emu8086.Inc'

data segment

num db "INPUT NUMBER : $"
line db 10,13

ends
ends

code segment
start:

mov ax,@data
mov ds,ax

lea dx,num
mov ah,09h
int 21h

call scan_num
push cx

mov ah, 02

cmp cl, 0
je exit

mov dl,10
int 21h
mov dl, 13
int 21h

mov dl, 2Ah
mov bl, 01
mov bh, 02
push bx

initial:
int 21h
cmp bl,cl
je exit
inc bl
cmp bl,bh
jne initial


pop bx
push dx

mov dl,10
int 21h
mov dl, 13
int 21h

add bh, 1

pop dx
push bx

jmp initial

exit:
int 20h
ends

DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS


end start

hi i tried to change ur code into this:

.model small
.stack 0100h
.data

num db "INPUT NUMBER : $"
line db 10,13

.code

mov ax,@data
mov ds,ax

lea dx,num
mov ah,09h
int 21h

call scan_num
push cx

mov ah, 02

cmp cl, 0
je exit

mov dl,10
int 21h
mov dl, 13
int 21h

mov dl, 2Ah
mov bl, 01
mov bh, 02
push bx

initial:
int 21h
cmp bl,cl
je exit
inc bl
cmp bl,bh
jne initial


pop bx
push dx

mov dl,10
int 21h
mov dl, 13
int 21h

add bh, 1

pop dx
push bx

jmp initial

exit:
int 21h

ends

DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS

end

but it still had errors
undefined symbol: SCAN_NUM

Like I said in my post above, That is NOT complete code. It is missing code for scan_num

Oh! i'm sorry, i'm lost in this i don't know how to debug this one

try to run the program in emu8086...

include 'emu8086.Inc'

data segment

num db "ENTER NUMBER : $"
line db 10,13

ends
ends

code segment
start:

mov ax,@data
mov ds,ax

lea dx,num
mov ah,09h
int 21h

call scan_num
push cx

mov ah, 02

cmp cl, 0
je exit

mov dl,10
int 21h
mov dl, 13
int 21h

mov dl, 2Ah
mov bl, 01
mov bh, 02
push bx

initial:
int 21h
cmp bl,cl
je exit
inc bl
cmp bl,bh
jne initial


pop bx
push dx

mov dl,10
int 21h
mov dl, 13
int 21h

add bh, 1

pop dx
push bx

jmp initial

exit:
int 20h
ends

DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS


end start

run the program in emu8086 and don't change any thing..

but i want it to run in tasm

.model small
.stack 100h
.data
	num db "Enter number: $"
	line db 10, 13

.code

	mov ax, @data
	mov ds, ax
	
	lea dx, num
	mov ah, 09h
	int 21h

	push cx

	mov ah, 02

	cmp cl, 0
	je exit

	mov dl, 10
	int 21h
	mov dl, 13
	int 21h

	mov dl, 2ah
	mov bl, 01
	mov bh, 02
	push bx

initial:
	int 21h
	cmp bl, cl
	je exit
	inc bl
	cmp bl, bh
	jne initial

	pop bx
	push dx

	mov dl, 10
	int 21h
	mov dl, 13
	int 21h

	add bh, 1
	pop dx
	push bx

	jmp initial

exit:
	int 20h

end

so far this is my code

I added some compiler directives (that a86 will just ignore) that might be helpful to TASM

.model small
org 100h
.code
; Compiled with A86 (http://eji.com/a86/)
        mov ah, 09h
        mov dx, askAmount;
        int 21h                      ; Ask for amount
        mov si, storeAmount          ; Place to store the user name
getVal:
        mov ah, 01h
        int 21h                      ; Get input with echo
checkVal:        
        cmp al, 0dh                  ; 
        jz quit                      ; Quit if Carriage-return
        cmp al, 31h
        jl quit                      ; Quit if too low
        cmp al, 39h
        jg quit                      ; Quit if too high

keepVal:        
        mov [si], al                 ; Put entered char in storeAmount
printCrLf:
        mov dx, storeCRLF            ; print CR/LF
        call doPrint
printQuit:
        xor cx, cx
        mov cl, byte ptr[storeAmount];
        sub cl, 30h                  ; result (in CX) = num lines and stars
b4Stars:
        mov dx, finalStop            ; set pointer to NO asterisks
stars:        
        dec dx                       ; move back num to print per loop
        call doPrint
outer:
        loop stars                   ; loop til CX=0
        jmp quit
doPrint:
        mov ah, 09h
        int 21h
        ret
quit:
        int 20h                      ; *** DROP TO DOS ***
askAmount:   db 'Enter the number of asterisks [1-9] to print (CR to quit): $'
storeAmount: db '$'
storeCRLF:   db 0ah, 0dh
terminator:  db '$'
asterisks:   db '*********'
finalStop:   db 0ah, 0dh, '$'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.