Author Topic: Read in a file and display ascii symbols?  (Read 24778 times)

Offline XxWh1t3gh0stxX

  • Jr. Member
  • *
  • Posts: 13
Read in a file and display ascii symbols?
« on: November 28, 2012, 04:07:34 AM »
I am trying to read from a file and display the ascii symbols, but when I read in values I either only get the actual text and not ascii symbols.
Code: [Select]
; Compiling this code for 32-bit use:
;    nasm -f elf file.asm
;
;
;~.~. Definitions for readability: ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
        %define  SYS_EXIT   1
        %define  SYS_READ   3
        %define  SYS_WRITE  4

        %define  STDIN      0
        %define  STDOUT     1
        %define  STDERR     2

;~.~. Initialized data: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
SECTION .data
        Title:    db 'title.txt', 0             ; Everything from title.txt
        Board:    db 'cBoard.txt', 0            ; Board
        OpenFile: db 'r', 0                     ; Opens an existing text file for reading
;~. Uninitialized data: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
SECTION .bss
        TLENGTH EQU 72
        tLENGTH resb TLENGTH
;~.~. Program code: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
SECTION .text

        ; Place all your extern declarations in this area.
        extern fopen
        extern fclose
        extern fgets
        extern printf
        global main                            ; specify starting with main

main:
        nop
        xor ebx, ebx
        mov ebx, Title
        call DisplayTitle
        xor ebx, ebx
        mov ebx, Board
        call DisplayBoard
        jmp home
;~.~. Subroutines: ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
        ; Place all your subroutine code in this area.
DisplayTitle:
        push OpenFile
        push ebx
        call fopen
        add esp, 8

        cmp eax, 0
        jne continue1
        ret

DisplayBoard:
        push OpenFile
        push ebx
        call fopen
        add esp, 8

        cmp eax, 0
        jne continue2
        ret

continue1:
        mov ebx, eax
        jmp readln1

continue2:
        mov ebx, eax
        jmp readln2

readln1:
        push ebx
        push DWORD TLENGTH
        push tLENGTH
        call fgets
        add esp, 12
        cmp eax, 0
        jle done
        push tLENGTH
        call printf
        add esp, 4
        jmp readln1

readln2:
        push ebx
        push DWORD TLENGTH
        push tLENGTH
        call printf
        add esp, 12
        cmp eax, 0
        jle done
        jmp readln2

done:
        push ebx
        call fclose
        add esp, 4
        ret

;~.~. Procedures: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
        ; Place all your non-main procedure code in this area.

;~.~. The starting function: ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
    ; this satisfies some compilers
        ; Place all your code for the main function in this area.
home:
        ret                                    ; for main instead of exit

;~_~_~ (end of file) ~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_

I know that readln2 is wrong and that is were my error is, but I don't know how to read the file and display the ascii symbols.
Thanks for all the help and suggestions.

Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: Read in a file and display ascii symbols?
« Reply #1 on: November 28, 2012, 04:35:17 AM »
1.) Try using the "rb" mode with fopen.

2.) ASCII is text when you treat it as such. Read up how printf works, specifically how it can format things to be printed.

Offline XxWh1t3gh0stxX

  • Jr. Member
  • *
  • Posts: 13
Re: Read in a file and display ascii symbols?
« Reply #2 on: November 28, 2012, 04:44:08 AM »
k, 'rb' doesn't help, but I did fix the run-on error in readln2. So it still just displays the title and the text? could it be because I am using the extern fgets to read in the file? I didn't mention it earlier, but I am using the ASCII & PC Extended Characters - Code Page 437
Here is the edited file
Code: [Select]
;
; Compiling this code for 32-bit use:
;    nasm -f elf file.asm
;
;
;~.~. Definitions for readability: ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
        %define  SYS_EXIT   1
        %define  SYS_READ   3
        %define  SYS_WRITE  4

        %define  STDIN      0
        %define  STDOUT     1
        %define  STDERR     2

;~.~. Initialized data: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
SECTION .data
        Title:    db 'title.txt', 0             ; Everything from title.txt
        Board:    db 'cBoard.txt', 0            ; Everything from cBoard.txt
        OpenFile1: db 'r', 0                    ; Opens an existing text file for reading
        OpenFile2: db 'rb', 0
;~. Uninitialized data: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
SECTION .bss
        TLENGTH EQU 72
        tLENGTH resb TLENGTH
;~.~. Program code: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
SECTION .text

        ; Place all your extern declarations in this area.
        extern fopen
        extern fclose
        extern fgets
        extern printf
        global main                            ; specify starting with main

main:
        nop
        xor ebx, ebx
        mov ebx, Title
        call DisplayTitle
        xor ebx, ebx
        mov ebx, Board
        call DisplayBoard
        jmp home
;~.~. Subroutines: ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
        ; Place all your subroutine code in this area.
DisplayTitle:
        push OpenFile1
        push ebx
        call fopen
        add esp, 8

        cmp eax, 0
        jne continue1
        ret

DisplayBoard:
        push OpenFile2
        push ebx
        call fopen
        add esp, 8

        cmp eax, 0
        jne continue2
        ret

continue1:
        mov ebx, eax
        jmp readln1

continue2:
        mov ebx, eax
        jmp readln2

readln1:
        push ebx
        push DWORD TLENGTH
        push tLENGTH
        call fgets
        add esp, 12
        cmp eax, 0
        jle done
        push tLENGTH
        call printf
        add esp, 4
        jmp readln1

readln2:
        push ebx
        push DWORD TLENGTH
        push tLENGTH
        call fgets
        add esp, 12
        cmp eax, 0
        jle done
        push tLENGTH
        call printf
        add esp, 4
        jmp readln2

done:
        push ebx
        call fclose
        add esp, 4
        ret

;~.~. Procedures: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
        ; Place all your non-main procedure code in this area.

;~.~. The starting function: ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
    ; this satisfies some compilers
        ; Place all your code for the main function in this area.
home:
        ret                                    ; for main instead of exit
;~_~_~ (end of file) ~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Read in a file and display ascii symbols?
« Reply #3 on: November 28, 2012, 08:21:06 AM »
I'm not sure I understand what you're trying to do. This is pretty screwed up, but may serve to clarify the question, "do you mean something like this?":
Code: [Select]
;
; Compiling this code for 32-bit use:
;    nasm -f elf file.asm
;
;
;~.~. Definitions for readability: ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
        %define  SYS_EXIT   1
        %define  SYS_READ   3
        %define  SYS_WRITE  4

        %define  STDIN      0
        %define  STDOUT     1
        %define  STDERR     2

;~.~. Initialized data: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
SECTION .data
        Title:    db 'title.txt', 0             ; Everything from title.txt
        Board:    db 'cBoard.txt', 0            ; Everything from cBoard.txt
        OpenFile1: db 'r', 0                    ; Opens an existing text file for reading
        OpenFile2: db 'rb', 0
    fmt_cx db `%c 0x%2X\n`, 0

;~. Uninitialized data: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
SECTION .bss
        TLENGTH EQU 72
        tLENGTH resb TLENGTH
;~.~. Program code: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
SECTION .text

        ; Place all your extern declarations in this area.
        extern fopen
        extern fclose
        extern fgets
        extern printf
        global main                            ; specify starting with main

main:
        nop
        xor ebx, ebx
        mov ebx, Title
        call DisplayTitle
        xor ebx, ebx
        mov ebx, Board
        call DisplayBoard
        jmp home
;~.~. Subroutines: ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
        ; Place all your subroutine code in this area.
DisplayTitle:
        push OpenFile1
        push ebx
        call fopen
        add esp, 8

        cmp eax, 0
        jne continue1
        ret

DisplayBoard:
        push OpenFile2
        push ebx
        call fopen
        add esp, 8

        cmp eax, 0
        jne continue2
        ret

continue1:
        mov ebx, eax
        jmp readln1

continue2:
        mov ebx, eax
        jmp readln2

readln1:
        push ebx
        push DWORD TLENGTH
        push tLENGTH
        call fgets
        add esp, 12
        cmp eax, 0
        jle done
        push tLENGTH
        call printf
        add esp, 4
        jmp readln1

readln2:
        push ebx
        push DWORD TLENGTH
        push tLENGTH
        call fgets
        add esp, 12
        cmp eax, 0
        jle done

    mov esi, tLENGTH
.top:
    movzx eax, byte [esi]
    inc esi
    test eax, eax
    jz done
    push eax
    push eax
    push fmt_cx
    call printf
    add esp, 4 * 3
    jmp .top


;        push tLENGTH
;        call printf
;        add esp, 4
;        jmp readln2

done:
        push ebx
        call fclose
        add esp, 4
        ret

;~.~. Procedures: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
        ; Place all your non-main procedure code in this area.

;~.~. The starting function: ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
    ; this satisfies some compilers
        ; Place all your code for the main function in this area.
home:
        ret                                    ; for main instead of exit
;~_~_~ (end of file) ~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_

Best,
Frank


Offline XxWh1t3gh0stxX

  • Jr. Member
  • *
  • Posts: 13
Re: Read in a file and display ascii symbols?
« Reply #4 on: November 28, 2012, 06:47:48 PM »
I am trying to read in these characters
Code: [Select]
201 205 203 205 203 205 203 205 203 205 203 205 203 205 203 205 187
186 177 186 224 186 177 186 224 186 177 186 224 186 177 186 224 186
204 205 206 205 206 205 206 205 206 205 206 205 206 205 206 205 185
186 224 186 177 186 224 186 177 186 224 186 177 186 224 186 177 186
204 205 206 205 206 205 206 205 206 205 206 205 206 205 206 205 185
186 177 186 224 186 177 186 224 186 177 186 224 186 177 186 224 186
204 205 206 205 206 205 206 205 206 205 206 205 206 205 206 205 185
186 177 186 32 186 177 186 32 186 177 186 32 186 177 186 32 186
204 205 206 205 206 205 206 205 206 205 206 205 206 205 206 205 185
186 32 186 177 186 32 186 177 186 32 186 177 186 32 186 177 186
204 205 206 205 206 205 206 205 206 205 206 205 206 205 206 205 185
186 225 186 177 186 225 186 177 186 225 186 177 186 225 186 177 186
204 205 206 205 206 205 206 205 206 205 206 205 206 205 206 205 185
186 177 186 225 186 177 186 225 186 177 186 225 186 177 186 225 186
204 205 206 205 206 205 206 205 206 205 206 205 206 205 206 205 185
186 225 186 177 186 225 186 177 186 225 186 177 186 225 186 177 186
200 205 202 205 202 205 202 205 202 205 202 205 202 205 202 205 188
the output is supposed to be this for the board is in the attatchment

Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
Re: Read in a file and display ascii symbols?
« Reply #5 on: November 29, 2012, 12:55:34 AM »
This is the contents of the file you've attached

00000000   FF FE 54 25  50 25 66 25  50 25 66 25  50 25 66 25  50 25 66 25  50 25 66 25  ..T%P%f%P%f%P%f%P%f%P%f%
00000018   50 25 66 25  50 25 66 25  50 25 57 25  0D 00 0A 00  51 25 92 25  51 25 B1 03  P%f%P%f%P%W%....Q%.%Q%..
00000030   51 25 92 25  51 25 B1 03  51 25 92 25  51 25 B1 03  51 25 92 25  51 25 B1 03  Q%.%Q%..Q%.%Q%..Q%.%Q%..
00000048   51 25 0D 00  0A 00 60 25  50 25 6C 25  50 25 6C 25  50 25 6C 25  50 25 6C 25  Q%....`%P%l%P%l%P%l%P%l%
00000060   50 25 6C 25  50 25 6C 25  50 25 6C 25  50 25 63 25  0D 00 0A 00  51 25 B1 03  P%l%P%l%P%l%P%c%....Q%..
00000078   51 25 92 25  51 25 B1 03  51 25 92 25  51 25 B1 03  51 25 92 25  51 25 B1 03  Q%.%Q%..Q%.%Q%..Q%.%Q%..


so under no circumstances will you have any hope of achieving the results you expect in the previous post.

Secondly, "%c 0x%2X\n" is also inconsistent with your example.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Read in a file and display ascii symbols?
« Reply #6 on: November 29, 2012, 01:27:58 AM »
I think the "%c 0x%2X\n" format was my idea... and apparently I was doing it "backwards". As you point out, the pasted numbers don't match "1234.txt". I think I'm still confused...

Best,
Frank


Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: Read in a file and display ascii symbols?
« Reply #7 on: November 29, 2012, 02:37:25 AM »
0xFFFE... smells like a Unicode byte order mark.

Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: Read in a file and display ascii symbols?
« Reply #8 on: November 29, 2012, 03:11:23 AM »
Yep, definitely Unicode.

An ASCII checkerboard with alphas and betas for pieces is somewhat amusing.

If I had to take a guess, I'd say someone copied the to-be-printed example into notepad and saved it as Unicode instead of ASCII.

Unless your instructor/instructions specifically state that you are to be working with Unicode, do the following at the command prompt (in the folder with 1234.txt) to get the right format.

Code: [Select]
type 1234.txt > 1234.ascii.txt

1234.ascii.txt should then have the desired ASCII format.

Offline XxWh1t3gh0stxX

  • Jr. Member
  • *
  • Posts: 13
Re: Read in a file and display ascii symbols?
« Reply #9 on: November 29, 2012, 04:16:24 AM »
k, I think I am confused now too. What is in "1234.txt" is the desired result that is displayed when the file "cBoard.txt" is read in.

When I saved "1234.txt" I made the format as Unicode because it looked messy otherwise its just supposed to be a reference.

I am using the Code page 437 so everything in cBoard.txt should be the output as it is in "1234.txt"

So what is in "cBoard.txt" is the three-digit decimal form of the character number, from 000-255
and I am trying to get the character glyph to build the board
Meaning for example:
ASCII     glyph
 201   =   ?
 205   =   ?
 203   =   ?

etc.

so everything read from cBoard.txt will appear on the screen similar to what is in 1234.txt.

my problem originally was when i was reading from the file it takes whats in the file and just displays whats in it. This is all good with the title, but when I read in the board its not and I don't know how to make the characters convert to the glyphs?

This is where I am at right now with the code

Code: [Select]
; Purpose: CSc475, Project Title
;
; Description: This code displays the Checkers title
;
; Compiling this code for 32-bit use:
;    nasm -f elf file.asm
;
;
;~.~. Definitions for readability: ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
        %define  SYS_EXIT   1
        %define  SYS_READ   3
        %define  SYS_WRITE  4

        %define  STDIN      0
        %define  STDOUT     1
        %define  STDERR     2

;~.~. Initialized data: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
SECTION .data
        Title:    db 'title.txt', 0             ; Everything from title.txt
        Board:    db 'cBoard.txt', 0            ; Everything from cBoard.txt
        OpenFile1: db 'r', 0                    ; Opens an existing text file for reading
        OpenFile2: db 'r', 0
        ASCIIFormat: db '%s', 0
;~. Uninitialized data: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
SECTION .bss
        TLENGTH EQU 72
        tLENGTH resb TLENGTH
;~.~. Program code: .~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
SECTION .text

        ; Place all your extern declarations in this area.
        extern fopen
        extern fclose
        extern fgets
        extern printf
        global main                            ; specify starting with main

main:
        nop
        xor ebx, ebx                    ; set ebx to zero
        mov ebx, Title                  ; move the title.txt to ebx
        call DisplayTitle               ; call DisplayTitle
        xor ebx, ebx                    ; set ebx to zero
        mov ebx, Board                  ; move the cBoard.txt to ebx
        call DisplayBoard               ; call DisplayBoard
        jmp home                        ; jump to home
;~.~. Subroutines: ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
        ; Place all your subroutine code in this area.
DisplayTitle:
        push OpenFile1                  ; push address of open-for-read code "r"
        push ebx                        ; address of the name of the file is in ebx
        call fopen                      ; attempt to open the file for reading
        add esp, 8                      ; clean up stack

        cmp eax, 0                      ; fopen() returns null if attempted open failed
        jne .continue                   ; jump if not equal to local label continue
        ret                             ; return

.continue:
        mov ebx, eax                    ; save handle of opened file in ebx
        jmp .readln                     ; jump to local label readln

.readln:
        push ebx                        ; push file handle on the stack
        push DWORD TLENGTH              ; limit line length of text read
        push tLENGTH                    ; push address of the text in the file for buffer
        call fgets                      ; read a line of text from the file
        add esp, 12                     ; clean stack
        cmp eax, 0                      ; a returned null indicates error or EOF
        jle done                        ; if we get 0 in eax, close up and return
        push tLENGTH                    ; push address of tLength on the stack
        call printf                     ; call printf to display file
        add esp, 4                      ; clean stack
        jmp .readln                     ; jump back to local label readln

DisplayBoard:
        push OpenFile2                  ; push address of open-for-read code "r"
        push ebx                        ; address of the name of the file is in ebx
        call fopen                      ; attempt to open the file for reading
        add esp, 8                      ; clean up stack

        cmp eax, 0                      ; fopen() returns null if attempted open failed
        jne .continue                   ; jump if not equal to local label continue
        ret                             ; return

.continue:
        mov ebx, eax                    ; save handle of opened file in ebx
        jmp .readln                     ; jump to local label readln

.readln:
        push ebx                        ; push file handle on the stack
        push DWORD TLENGTH              ; limit line length of text read
        push tLENGTH                    ; push address of the text in the file for buffer
;       push ASCIIFormat                ; was trying to make it be ASCII here?
        call fgets                      ; read a line of text from the file
        add esp, 12                     ; clean stack
        cmp eax, 0                      ; a returned null indicates error or EOF
        jle done                        ; if we get 0 in eax, close up and return
        push tLENGTH                    ; push address of tLength on the stack
;       push ASCIIFormat                ; was trying to make it be ASCII here?
        call printf                     ; call printf to display file
        add esp, 4                      ; clean stack
        jmp .readln                     ; jump to local label readln

done:
        push ebx
        call fclose
        add esp, 4
        ret
home:
        ret                                    ; for main instead of exit

;~_~_~ (end of file) ~_~_~_~_~_~_~_~_~_~_

thanks and sorry for the confusion
« Last Edit: November 29, 2012, 04:22:34 AM by XxWh1t3gh0stxX »

Offline XxWh1t3gh0stxX

  • Jr. Member
  • *
  • Posts: 13
Re: Read in a file and display ascii symbols?
« Reply #10 on: November 29, 2012, 04:18:12 AM »
ok so this forum doesn't actually display the ASCII Glyphs, but you can find the code page 437 at
http://en.wikipedia.org/wiki/Code_page_437

Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: Read in a file and display ascii symbols?
« Reply #11 on: November 29, 2012, 06:18:40 AM »
As an encoding example, if I take the 8-bit ASCII character 0xC9 (the upper-left double-line corner symbol) and convert it to decimal form, I have the decimal number 201. However, ASCII is "binary" and decimal is not, so I have to use an intermediate representation form. Since I am already working with a universally accepted system such as ASCII, I can just store the number 201 in a file as the ASCII characters 0x32 0x30 0x31 in succession, and 201 is what you'll see when viewing the contents in a program such as notepad. Note that most hex editors illustrate this concept by having a binary/hexadecimal view and text view, side-by-side.

Now, if I wanted to make an assignment out of decoding a sequence of the above ASCII character encodings, how do you think you should go about doing that?

Offline XxWh1t3gh0stxX

  • Jr. Member
  • *
  • Posts: 13
Re: Read in a file and display ascii symbols?
« Reply #12 on: November 29, 2012, 10:59:14 PM »
k, I brought it down to bare basic, no c call, just bare. This is how I am making the the ASCII glyph to display. I am actually hardcoding the hex value instead of the decimal value, and as a test it works. now how can I implement this from a file. like read it in and display it do I have to change the read mode to read and write mode because when I was using the call fgets I just got what was actually in the file no manipulation just displaying what was in the file.
Code: [Select]
section .data

        msg db  0xc9,0xa
        len equ $ - msg

section .bss

section .txt

        global _start

_start:
        mov     edx,len
        mov     ecx,msg
        mov     ebx,1
        mov     eax,4
        int     0x80
        mov     eax,1
        int     0x80

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Read in a file and display ascii symbols?
« Reply #13 on: November 30, 2012, 01:51:53 AM »
Good plan, to go back to something simple and work back up. Do you see a "box-drawing" character? If you want to convince yourself that it doesn't matter how the numbers are represented, you could change it to:
Code: [Select]
    msg db 201, 10
... should be exactly the same thing. (Nasm converts from the "text" in your source code to "numbers")

I saved the "pasted in" text from up above (not "1234.txt" which Keith identified as Unicode) as "cBoard.txt", and wrote a simple-minded routine to open it, read it, and convert from text to numbers, and print 'em as "ascii" (strictly speaking, "true ascii" is 7 bit code). Doesn't look like a "board" of any kind, but I think that's a "code page" issue. Comes out all on one line. My homemade "atoi", besides returning the number in eax (only al is interesting) also returns "pointer to next character" in edx, and the "invalid" (not a decimal digit) character that made it quit in ecx (cl). I think what I want to do is to ignore any spaces (which I do), but when a linefeed comes up, print it. Still won't look like a "board" but might be closer...

I should think that if you want to do it with C library calls, rather than read it with fgets, fscanf might work. I don't know how to get fscanf to skip the spaces (sometimes one, sometimes two) and perhaps the linefeeds. Maybe alternate fscanf and fgetc? I've always considered scanf to be "unfriendly", so I've never learned how to use it.

I can post my attempt, if you want, but it's really sloppy and needs to be cleaned up and commented. You seem to be on the right track...

Best,
Frank


Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: Read in a file and display ascii symbols?
« Reply #14 on: November 30, 2012, 02:09:03 AM »
Doesn't look like a "board" of any kind, but I think that's a "code page" issue. Comes out all on one line.

The original file had CRLF newlines, which I would imagine are supposed to indicate an implicit line break.

Read a line in, print that line out in ASCII form, CRLF, repeat.