0

The output should be

XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX

5x10 OR 10x5

The requirement is that there should be LOOP, INC AND/OR DEC only.

This is what I did, the result is infinite loop:

.model small
.stack
.code 

start:

mov ah, 02h
mov cx, 10   

l1:

mov bx, 12    ; loop pababa n bente    

l2: 

mov dl,78h
int 21h    

loop l2   

dec bx

mov dl, 0dh ; carriage return
int 21h
mov dl, 0ah ;line feed
int 21h
mov cx, bx

loop l1

mov ah, 4ch
int 21h  

end start
2
  • Please format the code. And if you follow the logic you can clearly see why that happens. Commented Aug 1, 2015 at 23:53
  • You might want to include what specific assembler you are using? What platform is this for? Commented Aug 1, 2015 at 23:58

2 Answers 2

1

You should clearly separate the outer loop from the inner loop.
I've written your code using BX as the outer loop control variable and using CX as the inner loop control variable.

  mov ah, 02h   ;CONST for both loops

---- Start of outer loop ----
  mov bx, 5     ;Do 5 lines like in your example
l1:

---- Start of inner loop ----
  mov cx, 10    ;Put 10 characters on each line 
  mov dl, 'X'
l2:
  int 21h    
  loop l2
---- End of inner loop ----

  mov dl, 0dh   ;CR
  int 21h
  mov dl, 0ah   ;LF
  int 21h
  dec bx
  jnz l1
---- End of outer loop ----
Sign up to request clarification or add additional context in comments.

Comments

0

Your problem is that you are making bx 12 (mov bx, 12) at the beginning of loop 1, then decrementing it by 1 after loop 2, then assigning its value to cx at the end of loop 1. Bx will only ever be 12 or 11, and cx will only ever be 11.

I think your fix is to move the (mov cx, bx) line to before the l1: loop begins, not after it begins as you have it now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.