1

I made a little NASM program that reads it's first command line argument and prints it out. It works well with ascii input: running "myfile hello" returns "argv = hello", but if input string contains special letters such as õ, ä, ö, ü , they will respectively be shown as §, õ, ÷, ³.

My current code is:

section .data
    input dw `argv = %s\n` , 0

section .bss

section .text
    global _main
    extern _printf

_main:
    push ebp
    mov ebp,esp
    push esi
    
    mov esi, [ebp + 12]
    mov ebx, 1
    mov eax, [esi + ebx * 4]
    push eax
    
    push input
    call _printf
    
    pop esi
    mov esp, ebp
    pop ebp
    ret

and is compiled as

nasm -f win32 myfile.asm -o myfile.obj
gcc -m32 myfile.obj -o myfile.exe

How can it be changed so that it will work with any type of input?

EDIT:

Thanks for the useful comments. Setting my terminal code page to 1252 did indeed solve my problem's example case. However, I am interested in more general solution. For example, I am still unable to print cyrillic characters freely.

I tried using unicode code page (65001), but it then ignores any non-ascii characters. Also tried to use code page 1251 directly. Then it could "translate" my õ,ä,ö,ü characters as Russian х,д,ц,ь; respectively. However inputting any actual Slavic letters will output just question marks. How can I solve it properly?

tanler
  • 9
  • 3
  • 1
    You face a [mojibake](https://en.wikipedia.org/wiki/Mojibake) case (*example in Python for its universal intelligibility*): `'õäöü'.encode( 'cp1252').decode( 'cp850')` returns `§õ÷³`. I suppose that the issue has nothing to do with `NASM`. Check (and change) code page for terminal (from any of `['cp775', 'cp850', 'cp857', 'cp858']` to any of `['cp1252', 'cp1254', 'cp1257']` - or vice versa, not sure…) – JosefZ Mar 16 '23 at 13:36
  • Perhaps if you need more help [edit] your question to show the output of `chcp` where you get the erroneous output. Perhaps see also [the Stack Overflow `character-encoding` tag info page](/tags/character-encoding/info) – tripleee Mar 16 '23 at 14:27

0 Answers0