Jump to content

ASCII table help

- - - - -

  • Please log in to reply
5 replies to this topic

#1
kkb123

kkb123

    Newbie

  • Members
  • Pip
  • 3 posts
Hi. Please help me on this...

Building an ascii table with 80x25 screen size (2000)

This is the first page...


	push ax

	push bx

	push cx

	push dx

	

	mov bx, 392

	mov byte ptr es:[bx], 'A'

	mov byte ptr es:[bx+2], 'S'

	mov byte ptr es:[bx+4], 'C'

	mov byte ptr es:[bx+6], 'I'

	mov byte ptr es:[bx+8], 'I'

	mov byte ptr es:[bx+12], 'T'

	mov byte ptr es:[bx+14], 'A'

	mov byte ptr es:[bx+16], 'B'

	mov byte ptr es:[bx+18], 'L'

	mov byte ptr es:[bx+20], 'E'

	

	

; 480

; column labels

	mov bx, 660

	mov byte ptr es:[bx],  'D'

	mov byte ptr es:[bx+2],  'E'

	mov byte ptr es:[bx+4],  'C'


	mov byte ptr es:[bx+8],  'H'

	mov byte ptr es:[bx+10],  'E'

	mov byte ptr es:[bx+12],  'X'


	mov byte ptr es:[bx+18],  'B'

	mov byte ptr es:[bx+20],  'I'

	mov byte ptr es:[bx+22],  'N'

	mov byte ptr es:[bx+24],  'A'

	mov byte ptr es:[bx+26],  'R'

	mov byte ptr es:[bx+28],  'Y'


	mov byte ptr es:[bx+34],  'C'

	

	mov byte ptr es:[bx+46],  'D'

	mov byte ptr es:[bx+48],  'E'

	mov byte ptr es:[bx+50],  'C'

	

	mov byte ptr es:[bx+54],  'H'

	mov byte ptr es:[bx+56],  'E'

	mov byte ptr es:[bx+58],  'X'


	mov byte ptr es:[bx+64],  'B'

	mov byte ptr es:[bx+66],  'I'

	mov byte ptr es:[bx+68],  'N'

	mov byte ptr es:[bx+70],  'A'

	mov byte ptr es:[bx+72],  'R'

	mov byte ptr es:[bx+74],  'Y'


	mov byte ptr es:[bx+78],  'C'


	mov byte ptr es:[bx+90],  'D'

	mov byte ptr es:[bx+92],  'E'

	mov byte ptr es:[bx+94],  'C'

	

	mov byte ptr es:[bx+98],  'H'

	mov byte ptr es:[bx+100],  'E'

	mov byte ptr es:[bx+102],  'X'


	mov byte ptr es:[bx+108],  'B'

	mov byte ptr es:[bx+110],  'I'

	mov byte ptr es:[bx+112],  'N'

	mov byte ptr es:[bx+114],  'A'

	mov byte ptr es:[bx+116],  'R'

	mov byte ptr es:[bx+118],  'Y'


	mov byte ptr es:[bx+122],  'C'


	mov bx, 820


	c1:

     MOV CX, 256                  ; initialize CX

     

     MOV AH, 2                    ; set output function  

     MOV DL, 0                    ; initialize DL with first ASCII character


     @LOOP:                       ; loop label

		INT 21h


       INC DL                     ; increment DL to next ASCII character

       DEC CX                     ; decrement CX

     JNZ @LOOP                    ; jump to label @LOOP if CX is 0


     MOV AH, 4CH                  ; return control to DOS

     INT 21H

 loop c1

	pop dx

	pop cx

	pop bx

	pop ax

	

	ret


Without c1 I can print the table outline.... but when I have that in the code, the table contents get overwritten..

Originally

Quote

           ASCII TABLE
   DEC HEX BINARY C    DEC HEX BINARY C

〔MENU HELP〕

Now I am getting

Quote

           ASCII TABLE

〔MENU HELP〕

<256 ASCII characters here.....>


Moreover, how do I print the character one at a time? I want to print the character in the format I set (as shown above...)
Thank you!

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
You're writing the characters out using an interrupt. Since you're putting the characters into memory manually, the system doesn't move the cursor accordingly, so it still thinks the cursor is at 0,0. When you use int 21h to print it out...bam. Whatever was in the location for 0,0 gets overwritten. Don't mix the two, as it's bound to backfire like it did here.

You have a few options:
1) Use int 10h, ah=02h to set the cursor position as necessary. Whenever you print out the string, the cursor is moved automatically, so you only need it when skipping lines or columns.
2) Put everything in memory manually. If you want to do this, use the string instructions like so:


section .data

str_ascii_table_len:    dw 11

str_ascii_table:        db "A", 0x07, "C", 0x07, "I", 0x07, "I", 0x07, " ", 0x07,

                        db "T", 0x07, "A", 0x07, "B", 0x07, "L", 0x07, "E", 0x07


section .text

mov     si, str_ascii_table         ; source string address

mov     cx, str_ascii_table_len     ; source string length in words


mov     ax, 0xb800                  ; set ES to point to video memory seg

mov     es, ax


mov     di, 392                     ; set DI to point to video memory offset


cld                                 ; make sure pointers are incremented, not decremented

rep     movsw                       ; write the string in


The 0x07 are the default attributes for the terminal text. If you want to skip over them, then just use a normal loop and increment di before the next write.

FYI the control characters are going to mess you up, especially 0x09, 0x0a, and 0x0d. Those are the tab, linefeed, and carriage return characters respectively, equivalent to \t and \n in C/C++ -style code. I recommend printing those as spaces.
sudo rm -rf /

#3
kkb123

kkb123

    Newbie

  • Members
  • Pip
  • 3 posts
Hi.
Thank you for the reply.

I have a very limited amount of knowledge in assembler. So I don't think #2 would work out for me...

Right now I have this

    MOV CX, 256                  ; initialize CX

    MOV AH, 02h                   ; set output function  

    MOV DL, 0                    ; initialize DL with first ASCII character


    loop1:                       ; loop label

	mov ah, 02h

	mov bx, 2

    int 10h

	mov ah, 02h


    INC DL                     ; increment DL to next ASCII character

    DEC CX                     ; decrement CX

    JNZ loop1                    ; jump to label @LOOP if CX is 0

	 

	mov ah, 02h

    int 10h

It's right below the code portion which displays the title of the columns
but I am not getting any output for the ASCII characters....

I am sry if I am being stupid....

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
To move the cursor:
AH = 02h
BH= page number, just set to 0
DH = row
DL = column

You're going to need to change which registers you use.
sudo rm -rf /

#5
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
You can set the cursor to the desired values:
push es       ;; save ES 

xor ax, ax 

mov es, ax       ;; Put 0 into ES 

mov byte [es:450h], 4  ;; Set the cursor to column 4. 

mov byte [es:451h], 17 ;; Set the cursor to row 17. 

pop es                         ;; restore ES 
The cursor won't jump to (4, 17) until the next time you write to the screen; however, it is possible to change the cursor position right away by talking to the 6845 video controller chip. The starting (16-bit) I/O port address for that can be found at memory location 0x463.

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Considering the level the OP appears to be at, I wouldn't recommend that just yet.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users