16 Bit Assembler Vertical Bar Loop

In summary, the conversation is about creating a program using 16 bit Assembler that displays a vertical bar character moving left to right and then back right to left across the screen. The program also includes a loop for reversing the direction and a subroutine called "waste" which wastes time. However, there is a bug in the code that needs to be fixed.
  • #1
Babiloo
1
0

Homework Statement


Create a program that displays a vertical bar character ‘|’ moving left to right in 79 positions across the screen, then back right to left across the screen.


Homework Equations


(16 bit Assembler)


The Attempt at a Solution


Code:
	.model small
	.stack 100h
	.data
bar	db	8,' ','|','$'
bar2	db	8,' ',8,8,'|','$'
		x dw 500

	.code
bars 	proc
	mov 	AX, @data
	mov 	ds, AX

	mov 	dl,'|'	
	mov	ah,2h
	int	21h

	mov	cl,79

	again:

	mov	ah,9h
	lea 	dx,bar
	int	21h

	call	waste
	dec	cl
	Jnz again

	mov	ah,9h
	lea 	dx,bar2
	int	21h

	call	waste
	dec	cl
	Jnz again

bars	endp
	waste	proc

	push	ax
	push	bx
	push 	cx
	push	dx

	again2:

	mov	cx,79
	
	again3:

	mov	ax,79
	mul	x
	dec	cx
	jnz	again3
	dec	ax
	jnz	again2
	
	pop	dx
	pop 	cx
	pop	bx
	pop 	ax

	ret
waste 	endp
	end 	waste
	end 	bars
 
Physics news on Phys.org
  • #2
So "waste" just wastes time.
You do have a bug. Your loop for reversing the direction goes to "again" instead of the top of the second "mov ah,9h".
 

FAQ: 16 Bit Assembler Vertical Bar Loop

1. What is a 16-bit assembler?

A 16-bit assembler is a programming language that allows a computer to execute instructions written in machine code, which is a low-level language consisting of binary code that can be directly understood by the computer's processor. This type of assembler is designed to work with 16-bit processors, which were commonly used in computers during the 1970s and 1980s.

2. What is a vertical bar loop in 16-bit assembler?

A vertical bar loop is a type of loop commonly used in 16-bit assembler programming. It involves using the vertical bar character (|) to indicate the start and end of the loop, and using the CX register to specify the number of iterations. This type of loop is often used for repetitive tasks such as data manipulation or program flow control.

3. How do you implement a vertical bar loop in 16-bit assembler?

To implement a vertical bar loop in 16-bit assembler, you will need to use the LOOP instruction and the CX register. First, you will need to initialize the CX register with the number of iterations you want the loop to run. Then, you will use the vertical bar character (|) to indicate the start and end of the loop. Within the loop, you will place the instructions that you want to be repeated, and use the LOOP instruction to decrease the value of CX and jump back to the beginning of the loop until CX reaches 0.

4. What are the advantages of using a vertical bar loop in 16-bit assembler?

Using a vertical bar loop in 16-bit assembler can have several advantages. One of the main advantages is that it allows for efficient and compact code, as the loop can be easily repeated without needing to write out each instruction multiple times. Additionally, vertical bar loops are flexible and can be easily modified to fit different program requirements. They also provide a clear and organized way to structure repetitive code.

5. Are there any disadvantages to using a vertical bar loop in 16-bit assembler?

While vertical bar loops can be useful in certain situations, they may not always be the most efficient solution. They can also be more difficult to debug and maintain, as any errors within the loop could potentially cause the program to crash. Additionally, vertical bar loops may not be suitable for more complex programming tasks, as they are limited in their capabilities compared to other types of loops or control structures.

Similar threads

Back
Top