Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

THE PROBLEM: Design and write a program in MASM that will prompt the user to enter an integer value. This integer value will be used

THE PROBLEM: Design and write a program in MASM that will prompt the user to enter an integer value. This integer value will be used by the program to print out a series of right triangles built out of asterisks '*'. Each of the triangles will be printed out one at a time using loops. Each of the triangles should also be between three and nine asterisks high, and the same number across, but in different configurations.

Example:

Input : 3

*

* *

* * *

-

* * *

* *

*

-

-* * *

- - * *

- - - *

-

- - - *

- - * *

- * * *

My code does not do this, it is the last bit line4

org 100h

.model small

.stack 64

.data

;Question the user of the input. input db "Enter the size for the triangles, between 3 to 9, or 0 to quit: $"

size dw ?

.code

main proc mov AX, @data ;move location of data segment into AX mov DS, AX ;DS now points to the data segment prompt: mov AH, 09h ;opcode to print a string lea DX, input ;string to print out int 21h mov AH, 01h ;opcode to read in single charcter input int 21h cmp AL, '0' ;checking to see if user input is '0' to start a quit je exit

sub AL, '0' ;convert user into literal value mov AH, 0 ;may not be required, blacks out top half of AX mov size, AX ;copy of literal vaue into variable size mov CX, AX ;copy value in AX into the count (CX) register ;cx count down mov BX, 1 ;set up BX for star counter loop. call crlf ;call crlf proc for carriage return / new line ;First Triangle lines1: push CX ;store the out (lines) loop mov CX, BX ;the start to print out also moves it stars1: mov AH, 02h ;opcode to print a single charater mov DL, '*' ;charater to print out int 21h loop stars1 ;end stars loop call crlf inc BX ;increment BX for stars loop pop CX ;recover CX for outer lines loop loop lines1 ;call crlf proc call crlf ;call crlf proc for carriage return / new line mov CX, size mov BX, 1 ;reload CX with the size copy for next triangle ;Second Triangle lines2: push CX ;stroe the outer (lines) loop value stars2: mov AH, 02h ;opcode to print a single charater mov DL, '*' ;charater to print out int 21h loop stars2 ;end stars2 loop call crlf ;call crlf proc pop CX ;recover value for outer loop loop lines2 ;end lines loop call crlf ;call crlf proc mov CX, size ;reload CX with copy of size for next triangl mov BX, 1 ;set up BX for star loop ;Third Triangle lines3: push CX ;push copy of CX onto stack for lines loop mov CX, BX ;the number of spaces to print out spaces1: mov AH, 02h ;opcode to print single character mov DL, ' ' ;blank space to print out int 21h loop spaces1 ;end spaces loop pop CX ;recover value into CX for stars loop push CX ;push CX for outer lines loop stars3: mov AH, 02h ;opcode to print a single charater mov DL, '*' ;charater to print out int 21h loop stars3 ;end stars_3 loop call crlf ;call crlf proc inc BX ;add one to BX for next line pop CX ;recover CX four outler lines loop loop lines3 call crlf ;call crlf proc mov CX, size mov BX, 1 ;set up CX with copy of size for next triangl ;Four Triangle ;take the spaces code from triangle 3 and adapt it for triangle 4. ;use the rest of triangle 2 as a reference point. lines4: push CX ;push copy of CX onto stack for lines loop spaces2: mov AH, 02h ;opcode to print single character mov DL, ' ' ;blank space to print out int 21h loop spaces2 ;end spaces loop pop CX ;recover value into CX for stars loop push CX ;push CX for outer lines loop stars4: mov AH, 02h ;opcode to print a single charater mov DL, '*' ;charater to print out int 21h loop stars4 ;end stars4 loop call crlf ;call crlf proc pop CX ;recover CX four outler lines loop loop lines4 call crlf exit: mov AX, 4C00h ;opcode to terminate program int 21h main endp

crlf proc mov AH, 02h mov DL, 13 int 21h mov DL, 10 int 21h ret

crlf endp end main

MY code does this

*

* *

* * *

-

* * *

* *

*

-

- * * *

- - * *

- - - *

-

- - - * * *

- - * *

- *

please help me get the correct one for the last one

- - - *

- - * *

- * * *

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ai And The Lottery Defying Odds With Intelligent Prediction

Authors: Gary Covella Ph D

1st Edition

B0CND1ZB98, 979-8223302568

More Books

Students explore these related Databases questions