2 Replies - 579 Views - Last Post: 01 March 2019 - 10:45 AM

#1 khnkhymkh   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-February 19

Assembly How to loop character in user-defined counter

Posted 21 February 2019 - 06:22 AM

I'm a beginner in assembly8086 (Using DosBOX). We have an assignment to produce the following: https://learn-ap-southeast-1-prod-fleet02-xythos.s3-ap-southeast-1.amazonaws.com/5be3c7fe2b7fc/2374161?response-content-disposition=inline%3B%20filename%2A%3DUTF-8%27%27Screen%2520Shot%25202019-02-20%2520at%25206.06.02%2520AM.png&response-content-type=image%2Fpng&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20190221T130108Z&X-Amz-SignedHeaders=host&X-Amz-Expires=21600&X-Amz-Credential=AKIAJDDBGKVKR5QVHNHA%2F20190221%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Signature=da5ac1cb5a772047257c7d13c55b4864396fc484d8936c1e6ab85f70634c579e

I tried doing it and this is my sample code.

mov ah,9
lea dx,[100]	// Enter a character: $
int 21h
mov ah,1
int 21h
mov bl,al
mov ah,9
lea dx,[120]	// Enter a number: $
int 21h
mov ah,1
int 21h
mov [si],al
mov cx,[si]
mov ah,2		// 14e
mov dl,bl
int 21h
inc cx
loop 14e



The problem occurs when i inputted a number after Enter a number. It displays the correct character i inputted but it doesn't stop to the required number of loop. It simply spams the character infinitely.

Posted Image
This is the image.

Is This A Good Question/Topic? 0
  • +

Replies To: Assembly How to loop character in user-defined counter

#2 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2389
  • View blog
  • Posts: 4,522
  • Joined: 30-May 10

Re: Assembly How to loop character in user-defined counter

Posted 21 February 2019 - 08:38 AM

Some annotations to your code.
12	mov [si],al     // Where is SI pointing to?
13	mov cx,[si]     // Also note that '4' != 4.  '4' is decimal 52 in the ASCII character set.
14	mov ah,2        // 14e
15	mov dl,bl
16	int 21h
17	inc cx          // The usual form is to initialise cx with 'N' and then do 'dec cx' to count down to 0
18	loop 14e   // There are such things as labels, so you don't have to manually count things


Was This Post Helpful? 0
  • +
  • -

#3 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,113
  • Joined: 03-April 12

Re: Assembly How to loop character in user-defined counter

Posted 01 March 2019 - 10:45 AM

The 'loop'-instruction does the decrementing.

Quote

Performs a loop operation using the RCX, ECX or CX register as a counter (depending on whether address size is 64 bits, 32 bits, or 16 bits). Note that the LOOP instruction ignores REX.W; but 64-bit address size can be over-ridden using a 67H prefix.

Each time the LOOP instruction is executed, the count register is decremented, then checked for 0. If the count is 0, the loop is terminated and program execution continues with the instruction following the LOOP instruction. If the count is not zero, a near jump is performed to the destination (target) operand, which is presumably the instruction at the beginning of the loop.

https://www.felixclo...x86/loop:loopcc

Incrementing CX counter-affects the loop-instruction.

This post has been edited by turboscrew: 01 March 2019 - 10:46 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1