【问题标题】:Clean console on assembly组装时清洁控制台
【发布时间】:2015-05-14 21:26:35
【问题描述】:

C for Assembly 上是否存在类似于system("cls"); 的内容?

我正在使用 NASM 进行编译,并且正在使用 x86 linux。

更新 1:这是我修改后的代码以集成建议:

section .data

%define SC_write        4   ; eax = write(ebx, ecx, edx)
%define ESC         033q


MAX_PALAVRA equ 40

(...)

num1        dd  0
num2        dd  0
result      dd  0
tamstr      dd  0

section .bss
strnum      resb    MAX_PALAVRA
opc     resb    2

section .text

global _start

   refresh:
        mov eax, ESC | ('[' << 8) | (BOTTOMROW << 16)
        stosd
        mov eax, ';0H' | (SI << 24)
        stosd
        mov edx, edi
        mov edi, outbuf
        mov ecx, edi
        sub edx, ecx
        xor ebx, ebx
        lea eax, [byte ebx + SC_write]
        inc ebx
        int 0x80

_start:

mov eax, ds
mov es, eax

干杯

【问题讨论】:

  • 我已经尝试了该链接上的代码,但是在编译时它给了我“错误:移位运算符可能只应用于标量值”和“错误:'|'运算符只能应用于标量值"
  • 发布您的代码或屏幕截图,看看您在做什么。
  • system("cls") 是一个可怕的构造,但这只是启动一个外部程序。当然你也可以从 asm 启动外部程序。
  • 你总是可以走老路,输出一堆换行符到控制台。

标签: linux assembly system nasm


【解决方案1】:

模仿clear 命令在.data 部分中的终端:

ClearTerm: db   27,"[H",27,"[2J"    ; <ESC> [H <ESC> [2J
CLEARLEN   equ  $-ClearTerm         ; Length of term clear string

那么每当你想清除终端时:

mov eax, 4                          ; Specify sys_write call
mov ebx, 1                          ; Specify File Descriptor 1: Stdout
mov ecx, ClearTerm                  ; Pass offset of terminal control string
mov edx, CLEARLEN                   ; Pass the length of terminal control string
int 80h

【讨论】:

    猜你喜欢
    • 2015-11-21
    • 1970-01-01
    • 2011-08-17
    • 2017-04-14
    • 1970-01-01
    • 2014-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多