assembly - 无法在 FASM 或 NASM 中使用 wprintf 打印 Unicode 字符串

标签 assembly x86 x86-64 nasm fasm

我在使用 FASM(平面汇编器)中的 wprintf 函数打印 Unicode 字符串时遇到问题。

我尝试了以下代码,但它产生随机输出(αñ╣αñ┐αñ¿αÑìαñ┐):


format PE64 console
entry start

include './include/win64w.inc'
include './include/macro/proc64.inc'
include './include/encoding/utf8.inc'

;======================================
section '.data' data readable writeable
;======================================
;unicode for हिन्दी
wunicode_string dw  0xe0, 0xa4, 0xb9, 0xe0, 0xa4, 0xbf, 0xe0, 0xa4, 0xa8, 0xe0, 0xa5, 0x8d, 0xe0, 0xa4, 0xbf



;=======================================
section '.code' code readable executable
;=======================================

start:
    
    mov rax, 0
    ccall [wprintf], "%ls", wunicode_string
   

    ccall   [getchar]                   ; I added this line to exit the application AFTER the user pressed any key.
    stdcall [ExitProcess],0             ; Exit the application

;====================================
section '.idata' import data readable
;====================================

library kernel,'kernel32.dll',        msvcrt,'msvcrt.dll'

import  kernel,        ExitProcess,'ExitProcess'

import  msvcrt,        printf,'printf', wprintf, 'wprintf',       getchar,'_fgetchar'

最佳答案

如果我们设置正确的code page,它会显示正确的输出对于我们可以在 FASM 中执行的控制台(也可以在 NASM 中工作),如下所示:

format PE64 console
entry start

include './include/win64a.inc'
include './include/macro/proc64.inc'


;=======================================
section '.code' code readable executable
;=======================================

start:

    ccall   [SetConsoleOutputCP], 65001
    ccall   [printf], "%s", "हिन्दी"


    ccall   [getchar]                   ; I added this line to exit the application AFTER the user pressed any key.
    stdcall [ExitProcess], 0            ; Exit the application

;====================================
section '.idata' import data readable
;====================================

library kernel,'kernel32.dll',\  
        msvcrt,'msvcrt.dll'

import  kernel,\  
        ExitProcess,'ExitProcess',\  
        SetConsoleOutputCP, 'SetConsoleOutputCP'

import  msvcrt,\  
        printf,'printf',\  
        getchar,'_fgetchar'

我使用过 printf,但它也适用于 wprintf

关于assembly - 无法在 FASM 或 NASM 中使用 wprintf 打印 Unicode 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76394710/

相关文章:

汇编PC相对寻址模式

assembly - 交换汇编语言中字符串中的字母 8086

assembly - 在引导加载程序中启动之前的 cli

linux - 在 nasm 汇编 intel x86 中获取数字而不是 Ascii

c++ - 在不使用其他变量的情况下用 C++ 编写程序集

c - 内核环境 : RSDP points to invalid RSDT

x86 - 调用门、中断门、陷阱门的区别?

linux - 尝试使用 scanf 存储两个数字,但程序崩溃

c - x86-64 汇编到 C

c - 为什么 proc/self/maps 没有正确显示映射