执行asm programm之后,不要在shell中换行。 [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 $8,%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 $2,%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 $0,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 $0,%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 $1,%ebx               # EBX = file descriptor (1 = stdout)
    movl (%esp),%ecx           # ECX = address of message
    movl $4,%eax               # syscall number (4 = write)
    int $0x80                   # call kernel by interrupt

    addl $4,%esp               # move ESP to next argument (1 argument = 4 bytes)
    decl arguments              # decrement the number of arguments
    movl $0,counter            # reset the counter of bytes
    jmp _arg                    # jump to the top of _arg

_print_white_space:
    movl $1,%edx               # EDX message length
    movl $1,%ebx               # EBX = file descriptor (1 = stdout)
    movl $white_space,%ecx     # ECX = address of message (startaddress)
    movl $4,%eax               # syscall number (4 = write)
    int $0x80                   # call kernel by interrupt
    jmp _numberOfBytes          # jump to _numberOfBytes --> still arguments left to print

_without_lf:
    addl $4,%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 $0,%ebx
     movl $1,%eax
     int $0x80

这是我程序的输出

执行asm programm之后,不要在shell中换行。 [AT&T]

$ PS1,$ PS1和常规echo命令的输出:

执行asm programm之后,不要在shell中换行。 [AT&T]

字节数是单词“ Hello”中的6个,因此结尾为空

执行asm programm之后,不要在shell中换行。 [AT&T]

sky03191 回答:执行asm programm之后,不要在shell中换行。 [AT&T]

您的程序正在运行。

像zsh一样,fish可以使您在程序输出后将提示带到新行,即使它没有以换行结尾。

发生这种情况时,在行的末尾会留下一个“⏎”。 (zsh会留下一个“%” IIRC)

因此,那些时候您看到一个“⏎”,您的程序就没有打印换行符。但是为了避免程序的输出和shell的提示符之间产生混淆,最好总是在新行上插入提示符,因此可以使用此技巧。

鱼不使用$ PS1或$ PS2,因此它们没有用。而是使用fish_prompt函数。

本文链接:https://www.f2er.com/2782618.html

大家都在问