2

I need to draw (print) a stack and queue using assembly language. Can anyone suggest me the code using VGA graphics?

I tried to modify the code of drawing(printing) a rectangle. Here's what I have done:

DATA SEGMENT
       H DW 150
       W DW 30
       K DW 150     
       TEMP DW 0000
       TEMP2 DW 0000
       TEMP3 DW 0000    
DATA ENDS

CODE SEGMENT
    ASSUME CS:CODE,DS:DATA
  START :MOV AX,DATA
         MOV DS,AX

  START1:      
         MOV AH,00H
         INT 16H
         CMP AL,61H ;press a to close
         JZ END1
         CALL RECT

       RECT PROC
         MOV AH,0
         MOV AL,12H
         INT 10H

         MOV CX,W
         MOV DX,H
         MOV TEMP2,CX

         MOV BX,CX
         ADD BX,DX
         MOV TEMP,BX

         MOV AX,0C02H

  BACK:  INT 10H
         INC CX
         CMP CX,TEMP ;---top
         JNZ BACK

         MOV AX,0C30H

   BACK1:INT 10H
         INC DX
         CMP DX,CX ;--ver right
         JNZ BACK1

         MOV AX,0C02H

   BACK2:INT 10H
         DEC CX
         CMP CX,TEMP2 ;--bottom
         JNZ BACK2

         MOV AX,0C02H

   BACK3:INT 10H
         DEC DX
         CMP DX,CX ;--left
         JNZ BACK3

         MOV AH,07H
         INT 21H
         RET

         RECT ENDP

    END1:MOV AH,4CH
         INT 21H


    CODE ENDS
        END START

My already coded stack program is:

data segment 

 str1 db 0Ah, 0Dh,"CHOOSE OPERATION", 0Ah, 0Dh, '$'

 str2 db 0Ah, 0Dh,"P FOR PUSH",0ah,0dh,'$'

 str3 db 0A, 0Dh,"R FOR POP",0ah,0dh,'$'

 str8 db 0Ah, 0Dh,"D FOR DISPLAY",0ah,0dh,'$'

 str9 db 0Ah, 0Dh,"Any key for exit",0ah,0dh,'$'

 str4 db 0Ah, 0Dh,"Enter value to be pushed",0ah,0dh,'$'

 str5 db 0Ah, 0Dh,"Overflow",0ah,0dh,'$'

 str6 db 0Ah, 0Dh,"Do you want to continue? (y/n)",0ah,0dh,'$'

 str7 db 0Ah, 0Dh,"Empty stack",0ah,0dh,'$'

 str10 db 0Ah, 0Dh,"Popping..$"

 choose db 1 dup(0)

 top db 1 dup(0)

 temp db 1 dup(0)

 t db 1 dup(0)

 array db 100 dup(0)

 maxsize db 1 dup(0)
data ends

code segment

    assume cs:code, ds:data

    start: mov ax,data

           mov ds,ax

           mov top,00

           mov temp,00

           mov maxsize,10

           lea si, array

           lea di, array

    menu:


           mov dx, offset str1

           mov ah,09h

           int 21h

           mov dx, offset str2

           mov ah,09h

           int 21h

           mov dx, offset str3

           mov ah,09h

           int 21h

           mov dx, offset str8

           mov ah,09h

           int 21h

           mov dx, offset str9

           mov ah,09h

           int 21h

           mov ah,01

           int 21h

           cmp al, 'p'

           je p

           cmp al, 'r'


           je r

           cmp al, 'd'

           je d

           jmp e

   p:      cmp top,10

           jne x

           mov dx, offset str5

           mov ah,09h

           int 21h

           jmp menu


   x:      mov dx, offset str4

           mov ah,09h

           int 21h


           mov ah,01

           int 21h

           mov [si],al

           inc si

           inc top

           mov dx, offset str6

           mov ah,09h

           int 21h

           mov ah,01


           int 21h

           cmp al, 'y'

           je p

           jmp menu

   r:      cmp top,00

           jne y

           mov dx, offset str7

           mov ah,09h

           int 21h

           jmp menu

   y:      mov dx, offset str10

           mov ah,09h

           int 21h

           dec si

           dec top

           mov dl,[si]

           mov ah,02

           int 21h

           mov dx, offset str6

           mov ah,09h

           int 21h

           mov ah,01

           int 21h

           cmp al, 'y'

           je r

           jmp menu

   d:      cmp top,00

           jne zz

           mov dx, offset str7

           mov ah,09h

           int 21h

           jmp menu

   zz:     mov bl,top

           mov t,bl

           mov bx,si



   z:      dec si

           mov dl,[si]

           mov ah,02

           int 21h

           mov dl, 32

           mov ah,02

           int 21h

           dec t

           cmp t,00

           jne z

           mov si,bx

           jmp menu

   e:    int 3
code ends

end start

end
Michael
  • 52,337
  • 9
  • 68
  • 113
  • Looks like TASM? I noticed you didn't define a stack - might be a good idea. What are your problems, what errors? What does the program actually do? And what is it expected to do? – Michael Petch Sep 25 '15 at 05:47
  • Yes it is TASM. I've made a simple stack program with basic push, pop and display functions. I need to represent it in a visual stack using VGA graphics mode. – IT.enthusiastic Sep 25 '15 at 05:50
  • Oh I meant you never defined a stack in the program itself ;-). Usually TASM programs start with a MODEL directive like `MODEL SMALL` followed by a `STACK` directive. – Michael Petch Sep 25 '15 at 05:54
  • @MichaelPetch there are no errors as such.All I need to do is to print a stack on VGA graphics output screen. – IT.enthusiastic Sep 25 '15 at 05:55
  • 1
    _"I need to draw (print) a stack and queue using assembly language"_ doesn't qualify as a good problem description. It's far too vague, and it's unclear exactly what part of that you're having trouble with. Please ask a more specific question. – Michael Sep 25 '15 at 05:58
  • I want to make a interactive program in which by pushing a value in stack,I could see it in my graphical stack in VGA mode. My stack works fine without the VGA mode. I've simply declared an array for storing my values which are pushed and popped in the stack. I have trouble using the VGA mode as I'm totally new to this format. – IT.enthusiastic Sep 25 '15 at 06:03
  • look at this: [Graphics rendering](http://stackoverflow.com/a/21699076/2521214) see the VGA gfx mode part (it is in x86 Asm mixed with C++) and also this: [NoSignal demo in asm](http://stackoverflow.com/a/29296619/2521214) it might help a bit. Here [Battle](http://stackoverflow.com/a/29579522/2521214) another asm example of mine (tunneler like game) – Spektre Sep 25 '15 at 07:22
  • We have no idea how you want your data structure to be represented visually. And you still haven't explained what _specifically_ that's stopping you from achieving this yourself. Read some tutorials on mode 13h programming (or whatever VGA mode you're using), write some code, and if you run into a specific problem with that code, ask a question about _that_. – Michael Sep 25 '15 at 08:50

0 Answers0