输出寄存器将MASM控制台 [英] Outputting registers to the console with MASM

查看:307
本文介绍了输出寄存器将MASM控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我算是天开始学习ASM和​​我已经做了一些教程,甚至成功修改教程内容使用JMP和CMP等代替MASM。如果和。而宏。

I'm one day into learning ASM and I've done a few tutorials, and even successfully modified the tutorial content to use jmp and cmp, etc instead of the MASM .if and .while macros.

我决定尝试写的东西非常简单,开始之前,我继续更高级教程。我正在写一个斐波那契数发生器。这里是源我到目前为止有:

I've decided to try and write something very, very simple to begin with before I continue with more advanced tutorials. I'm writing a Fibonacci number generator. Here is the source I have so far:

.386
.model flat, stdcall

option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib

.code
start:

  mov eax, 1
  mov ecx, 1

  _a:

    push eax
    add  eax, ecx
    pop  ecx

    ; Jump to _b if there is an overflow on eax

    ; Print Values Here

  jmp _a

  _b:

  push 0
  call ExitProcess

end start

我打算把检查的EAX / ECX溢出,但现在我在屏幕上显示EAX / ECX的值只是有兴趣。

I intend to check for overflows on eax/ecx but right now I'm just interested in displaying the values of eax/ecx on the screen.

我知道如何从推。数据常量字符串的地址和调用的StdOut这是在Hello World教程中的第一个例子,但是这似乎是完全不同的(?)。

I know how to push the address of a constant string from .data and call StdOut which was the first example in the hello world tutorial, but this appears to be quite different (?).

推荐答案

有是微软本身提供的这个code

There is this code provided by Microsoft itself

http://support.microsoft.com/kb/85068

请注意,在16位系统中,这code输出AX寄存器。但你可以得到的想法,你只需要通过每个字符循环到AX值转换成ASCII字符。跳过中断部分,并使用您的StdOut函数。

Note that this code outputs AX register on 16 bit systems. But you can get the idea, you just need to convert AX value into ASCII characters by looping through each character. Skip the interrupts part and use your StdOut function.

 mov dx, 4          ; Loop will print out 4 hex characters.
nexthex:
          push dx            ; Save the loop counter.
          mov cl, 4          ; Rotate register 4 bits.
          rol ax, cl
          push ax            ; Save current value in AX.

          and al, 0Fh        ; Mask off all but 4 lowest bits.
          cmp al, 10         ; Check to see if digit is 0-9.
          jl decimal         ; Digit is 0-9.
          add al, 7          ; Add 7 for Digits A-F.
decimal:
          add al, 30h        ; Add 30h to get ASCII character.

          mov dl, al
          ;Use StdOut to print value of dl
           ;mov ah, 02h        ; Prepare for interrupt.
          ;int 21h            ; Do MS-DOS call to print out value.

          pop ax             ; Restore value to AX.
          pop dx             ; Restore the loop counter.
          dec dx             ; Decrement loop counter.
          jnz nexthex        ; Loop back if there is another character
                             ; to print.

在这里看到,以及:

See here as well:

<一个href=\"http://www.masm32.com/board/index.php?PHPSESSID=fa4590ba57dbaad4bc44088172af0b49&action=printpage;topic=14410.0\" rel=\"nofollow\">http://www.masm32.com/board/index.php?PHPSESSID=fa4590ba57dbaad4bc44088172af0b49&action=printpage;topic=14410.0

这篇关于输出寄存器将MASM控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆