[英]How is FASM a low level assembler and NASM a high level assembler?
[英]How do i Print out a number using fasm assembler?
我真的是汇编程序设计的新手,我正在学习尝试自己和课堂学习的一些东西。 因此,我的目标是显示存储在寄存器中的数字。 当我运行程序时,它将显示数字的字符值,因此,如果我要显示数字本身,我将如何处理。 这是我的代码,请提示我哪里出错了。 到目前为止,我们已经学会了移动指令和汇编中的其他一些基本知识。
#fasm#
mov ah,2
mov bh,66
add bh,1
mov dl,bh
int 21h
int 20h
use16 ;generate 16bit opcodes
org 0100h ;code offset for .COM program
mov ax,1976 ;ax = number to display
xor cx,cx ;cx = count = 0
mov bx,10 ;bx = number base = 10
.stack:
xor dx,dx ;dx:ax for div
div bx ;dx:ax = dx:ax div base
add dx,'0' ;dx into ascii
push dx ;stack it
inc cx ;increment counter
test ax,ax ;do again if not 0
jnz .stack
mov ah,02h ;DOS 1+ - WRITE CHARACTER TO STANDARD OUTPUT
.write:
pop dx ;unstack it
int 21h ;write
loop .write ;for each in count
mov ah,08h ;DOS 1+ - CHARACTER INPUT WITHOUT ECHO
int 21h ;read
int 20h ;DOS 1+ - TERMINATE PROGRAM
您可以使用win32 api(下面的示例)。 我建议您搜索Iczelion教程。 他们在MASM中。 FASM Iczelion示例在这里 。
format PE GUI 4.0
entry start
; macros for `invoke`, `cinvoke`, ...
include 'win32ax.inc'
; code section
section '.text' code readable writable executable
; text buffer for the number to display
buffer rb 64 ; 64 bytes
; program start
start:
; our number
mov eax, 1234
; printing EAX to buffer
cinvoke wsprintf, buffer, '%d', eax
; terminate string with zero
mov [buffer + eax], 0
; showing message
invoke MessageBox, 0, buffer, 'result', MB_OK
; calling exit
invoke ExitProcess, 0
section '.idata' import readable writable
library kernel32, 'KERNEL32.DLL',\
user32, 'USER32.DLL'
include 'api\kernel32.inc'
include 'api\user32.inc'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.