Assembly 输入一个整数时间值,后跟“0”:&引用;在SPARC汇编语言中

Assembly 输入一个整数时间值,后跟“0”:&引用;在SPARC汇编语言中,assembly,sparc,Assembly,Sparc,我试图要求用户按以下顺序输入时间值hours:min-例如,用户可以输入3:45。现在,我想得到小时值并用它做一些事情,然后我想得到分钟值并用它做一些其他事情 我正在使用mov%o0,%time存储时间值。然而,有两个问题: 如果用户在小时后输入:,程序将不会运行 我不知道如何分别得到小时和时间的值 任何帮助都将不胜感激 使用您拥有的任何服务来接受字符串输入,然后找到分隔符并解析每边的两个数字 更新:下面是一个示例实现 ! parse time in hh:mm format ! in:

我试图要求用户按以下顺序输入时间值
hours:min
-例如,用户可以输入
3:45
。现在,我想得到小时值并用它做一些事情,然后我想得到分钟值并用它做一些其他事情

我正在使用
mov%o0,%time
存储时间值。然而,有两个问题:

  • 如果用户在小时后输入
    ,程序将不会运行
  • 我不知道如何分别得到小时和时间的值

任何帮助都将不胜感激

使用您拥有的任何服务来接受字符串输入,然后找到分隔符并解析每边的两个数字


更新:下面是一个示例实现

! parse time in hh:mm format
! in: %o0 pointer to zero-terminated buffer
! out: %o0 hours, %o1 minutes
gettime:
    save %sp, -64, %sp
    ! look for the colon in the string
    ! for simplicity, assume it always exists
    mov %i0, %o0            ! use %o0 for pointer
colon_loop:
    ldub [%o0], %o1         ! load next byte
    cmp %o1, ':'
    bne colon_loop
    add %o0, 1, %o0
    ! ok, now we have start of minutes in %o0
    ! replace the colon by a zero
    ! and convert the minutes part
    call atoi
    stb %g0, [%o0-1]
    ! we now have the minutes in %o0, save it
    mov %o0, %i1
    ! convert the hours
    call atoi
    mov %i0, %o0
    ! we now have hours in %o0
    ! return with hours,minutes in %o0,%o1 respectively
    ret
    restore %o0, %g0, %o0

! simple atoi routine
! in: %o0 pointer to zero-terminated string of digits
! out: %o0 the converted value
atoi:
    mov %g0, %o1            ! start with zero
atoi_loop:
    ldub [%o0], %o2         ! load next character
    cmp %o2, 0              ! end of string?
    be atoi_done
    sub %o2, '0', %o2       ! adjust for ascii
    ! now multiply partial result by 10, as 8x+2x
    sll %o1, 3, %o3         ! 8x
    sll %o1, 1, %o1         ! 2x
    add %o1, %o3, %o1       ! 10x
    ! now add current digit and loop back
    add %o2, %o1, %o1
    b atoi_loop
    add %o0, 1, %o0
atoi_done:
    retl
    mov %o1, %o0

您是否尝试过用C编写代码,并使用
gcc-O-fverbose asm-S
获取生成的汇编代码……?我没有尝试过,但我想学习如何直接在assembly中编写它谢谢您的回答,您能告诉我详细信息吗?我真的不知道如何解决这个问题。更新了示例实现。非常感谢,您还在个人资料中写了“在irc.freenode.net上查找我作为Jester01”,但该网站不起作用,是否有其他方式与您联系?这不是一个网站,这是一个Internet中继聊天服务器。如果没有客户端,可以使用。