Fill with stars

STOSB stores AL at ES:DI and moves DI on. With the prefix REP it repeats CX times, so one instruction fills a whole buffer.

What to build

Read a digit n and print n stars, by filling a buffer with REP STOSB.

Requirements

  • Fill the buffer with n stars with a single REP STOSB.
  • Put a $ after the stars and print the buffer with service 9.
  • Print nothing else.

Input

One digit n from 1 to 9, then Enter.

Output

n stars on one line.

Constraints

1 ≤ n ≤ 9.

Example

Input:

5

Output:

*****

Why it works

REP STOSB repeats as long as CX is not 0, taking 1 from CX each time. It needs ES to point at the buffer, and CLD to make DI move forwards. The $ is stored by one more STOSB, and service 9 prints up to it.

Examples

Example 1 · Input
5
Expected output
*****
Example 2 · Input
1
Expected output
*

Hints

Hint 1

Set ES to the data segment as well as DS: MOV ES, AX after MOV DS, AX. STOSB writes to ES:DI.

Hint 2

CLD makes DI go up. Load AL with '*', DI with the buffer address and CX with n, then REP STOSB.

Hint 3

Store a '$' after the stars (MOV AL, '$' then STOSB) and print the buffer with AH = 9.

Solution

Show one correct solution (try it yourself first)
; Fill with stars
.MODEL SMALL
.STACK 100H
.DATA
    BUF DB 12 DUP(?)
.CODE
MAIN PROC
    MOV AX, @DATA
    MOV DS, AX
    MOV ES, AX
    CLD
    MOV AH, 1
    INT 21H
    SUB AL, '0'
    MOV CL, AL
    MOV CH, 0           ; CX = n
    LEA DI, BUF
    MOV AL, '*'
    REP STOSB           ; n stars
    MOV AL, '$'
    STOSB               ; the end mark
    LEA DX, BUF
    MOV AH, 9
    INT 21H
    MOV AH, 4CH
    INT 21H
MAIN ENDP
END MAIN

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: String instructions →