执行 asm 程序后不要在 shell 换行。 [美国电话电报公司]
Don't line break in shell after executing asm programm. [AT&T]
如标题所说,asm 程序执行后不应自动换行。我的程序是 linux 中 "echo" 命令的简化版本。它打印用户给出的参数。如果用户的第一个参数是“-n”,提示符应该在输出的右边,而不是换行。所以我的问题是如何在执行后强制不在 AT&T 中断行?
.code32
.section .data
lf: .ascii "-n" # Lf = line feed
withoutLF: .long 0 # helper flag
counter: .long 0 # is the counter of bytes of an argument
arguments: .long 0 # number of arguments
white_space: .ascii " " # is white space
.section .text
.globl _start
_start:
movl (%esp), %esi # gets the argument count of the stack to ESI
movl %esi, arguments # moves argument count to arguments variable
decl arguments # decrement counter
addl , %esp # move the esp to the actual arguments
### check if first argument is '-n' ###
movl (%esp), %esi # move first string to ESI
movl $lf, %edi # move second string to EDI
movl , %ecx # number of bytes which should be compared
cld # clear Flag D, wihtout clearance the compare ill occur in inverse order
rep cmpsb # the actual comparing of the 2 strings
jz _without_lf # if the same jump to _without_lf
_arg:
movl (%esp), %esi # moves argument of stack to ESI
cmpl [=11=], arguments # compares if there any arguments left
je _exit # out of arguments --> exit progamm
jmp _print_white_space # if NOT out of arguments --> print a white space
_numberOfBytes:
lodsb # load string in bytes from ESI --> saves byte in EAX
cmpb [=11=], %al # compare if byte is equal 0
je _print_arg # jumps to section to print the actual argument
incl counter # increment the counter (number of bytes)
jmp _numberOfBytes # jump to the beginning of _numberOfBytes (to read the left bytes)
_print_arg:
movl counter, %edx # EDX message length
movl , %ebx # EBX = file descriptor (1 = stdout)
movl (%esp), %ecx # ECX = address of message
movl , %eax # syscall number (4 = write)
int [=11=]x80 # call kernel by interrupt
addl , %esp # move ESP to next argument (1 argument = 4 bytes)
decl arguments # decrement the number of arguments
movl [=11=], counter # reset the counter of bytes
jmp _arg # jump to the top of _arg
_print_white_space:
movl , %edx # EDX message length
movl , %ebx # EBX = file descriptor (1 = stdout)
movl $white_space, %ecx # ECX = address of message (startaddress)
movl , %eax # syscall number (4 = write)
int [=11=]x80 # call kernel by interrupt
jmp _numberOfBytes # jump to _numberOfBytes --> still arguments left to print
_without_lf:
addl , %esp # move ESP to next argument of the stack
decl arguments # decrement arguments counter --> '-n' is not counted, just used
incl withoutLF # move 1 to withLF (helper flag)
jmp _arg
_exit: # exit the program
movl [=11=], %ebx
movl , %eax
int [=11=]x80
这是我程序的输出
$PS1、$PS1和普通回显命令的输出:
字节数是单词的 6 个 "Hello" 所以有一个空终止符
您的程序正在运行。
与 zsh 一样,fish 会在程序输出后让您的提示换行,即使它没有以换行结尾。
发生这种情况时,会在行尾留下一个“⏎”。 (zsh 留下一个“%”IIRC)
所以那些你能看到“⏎”的时候,你的程序已经没有打印换行符了。但是为了避免程序的输出和 shell 的提示之间的混淆,提示总是换行是很好的,所以使用了这个技巧。
而且 fish 不使用 $PS1 或 $PS2,所以这些都没有用。相反,它使用 fish_prompt
函数。
如标题所说,asm 程序执行后不应自动换行。我的程序是 linux 中 "echo" 命令的简化版本。它打印用户给出的参数。如果用户的第一个参数是“-n”,提示符应该在输出的右边,而不是换行。所以我的问题是如何在执行后强制不在 AT&T 中断行?
.code32
.section .data
lf: .ascii "-n" # Lf = line feed
withoutLF: .long 0 # helper flag
counter: .long 0 # is the counter of bytes of an argument
arguments: .long 0 # number of arguments
white_space: .ascii " " # is white space
.section .text
.globl _start
_start:
movl (%esp), %esi # gets the argument count of the stack to ESI
movl %esi, arguments # moves argument count to arguments variable
decl arguments # decrement counter
addl , %esp # move the esp to the actual arguments
### check if first argument is '-n' ###
movl (%esp), %esi # move first string to ESI
movl $lf, %edi # move second string to EDI
movl , %ecx # number of bytes which should be compared
cld # clear Flag D, wihtout clearance the compare ill occur in inverse order
rep cmpsb # the actual comparing of the 2 strings
jz _without_lf # if the same jump to _without_lf
_arg:
movl (%esp), %esi # moves argument of stack to ESI
cmpl [=11=], arguments # compares if there any arguments left
je _exit # out of arguments --> exit progamm
jmp _print_white_space # if NOT out of arguments --> print a white space
_numberOfBytes:
lodsb # load string in bytes from ESI --> saves byte in EAX
cmpb [=11=], %al # compare if byte is equal 0
je _print_arg # jumps to section to print the actual argument
incl counter # increment the counter (number of bytes)
jmp _numberOfBytes # jump to the beginning of _numberOfBytes (to read the left bytes)
_print_arg:
movl counter, %edx # EDX message length
movl , %ebx # EBX = file descriptor (1 = stdout)
movl (%esp), %ecx # ECX = address of message
movl , %eax # syscall number (4 = write)
int [=11=]x80 # call kernel by interrupt
addl , %esp # move ESP to next argument (1 argument = 4 bytes)
decl arguments # decrement the number of arguments
movl [=11=], counter # reset the counter of bytes
jmp _arg # jump to the top of _arg
_print_white_space:
movl , %edx # EDX message length
movl , %ebx # EBX = file descriptor (1 = stdout)
movl $white_space, %ecx # ECX = address of message (startaddress)
movl , %eax # syscall number (4 = write)
int [=11=]x80 # call kernel by interrupt
jmp _numberOfBytes # jump to _numberOfBytes --> still arguments left to print
_without_lf:
addl , %esp # move ESP to next argument of the stack
decl arguments # decrement arguments counter --> '-n' is not counted, just used
incl withoutLF # move 1 to withLF (helper flag)
jmp _arg
_exit: # exit the program
movl [=11=], %ebx
movl , %eax
int [=11=]x80
这是我程序的输出
$PS1、$PS1和普通回显命令的输出:
字节数是单词的 6 个 "Hello" 所以有一个空终止符
您的程序正在运行。
与 zsh 一样,fish 会在程序输出后让您的提示换行,即使它没有以换行结尾。
发生这种情况时,会在行尾留下一个“⏎”。 (zsh 留下一个“%”IIRC)
所以那些你能看到“⏎”的时候,你的程序已经没有打印换行符了。但是为了避免程序的输出和 shell 的提示之间的混淆,提示总是换行是很好的,所以使用了这个技巧。
而且 fish 不使用 $PS1 或 $PS2,所以这些都没有用。相反,它使用 fish_prompt
函数。