鱼C论坛

 找回密码
 立即注册
查看: 4291|回复: 2

求助求助

[复制链接]
发表于 2021-6-10 02:27:32 From FishC Mobile | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
用汇编语言完成一个字符串统计,要求分别出字母,数字,其他字符的个数
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-10 09:35:44 | 显示全部楼层
  1.         .file   "main.c"
  2.         .text
  3.         .section        .rodata
  4.         .align 8
  5. .LC0:
  6.         .string "letter: %lu, number: %lu, other: %lu\n"
  7.         .text
  8.         .globl  main
  9.         .type   main, @function
  10. main:
  11. .LFB0:
  12.         .cfi_startproc
  13.         pushq   %rbp
  14.         .cfi_def_cfa_offset 16
  15.         .cfi_offset 6, -16
  16.         movq    %rsp, %rbp
  17.         .cfi_def_cfa_register 6
  18.         subq    $32, %rsp
  19.         movq    $0, -24(%rbp)
  20.         movq    $0, -16(%rbp)
  21.         movq    $0, -8(%rbp)
  22.         jmp     .L2
  23. .L5:
  24.         call    __ctype_b_loc@PLT
  25.         movq    (%rax), %rdx
  26.         movl    -28(%rbp), %eax
  27.         cltq
  28.         addq    %rax, %rax
  29.         addq    %rdx, %rax
  30.         movzwl  (%rax), %eax
  31.         movzwl  %ax, %eax
  32.         andl    $1024, %eax
  33.         testl   %eax, %eax
  34.         je      .L3
  35.         addq    $1, -24(%rbp)
  36.         jmp     .L2
  37. .L3:
  38.         call    __ctype_b_loc@PLT
  39.         movq    (%rax), %rdx
  40.         movl    -28(%rbp), %eax
  41.         cltq
  42.         addq    %rax, %rax
  43.         addq    %rdx, %rax
  44.         movzwl  (%rax), %eax
  45.         movzwl  %ax, %eax
  46.         andl    $2048, %eax
  47.         testl   %eax, %eax
  48.         je      .L4
  49.         addq    $1, -16(%rbp)
  50.         jmp     .L2
  51. .L4:
  52.         addq    $1, -8(%rbp)
  53. .L2:
  54.         call    getchar@PLT
  55.         movl    %eax, -28(%rbp)
  56.         cmpl    $-1, -28(%rbp)
  57.         jne     .L5
  58.         movq    -8(%rbp), %rcx
  59.         movq    -16(%rbp), %rdx
  60.         movq    -24(%rbp), %rax
  61.         movq    %rax, %rsi
  62.         leaq    .LC0(%rip), %rax
  63.         movq    %rax, %rdi
  64.         movl    $0, %eax
  65.         call    printf@PLT
  66.         movl    $0, %eax
  67.         leave
  68.         .cfi_def_cfa 7, 8
  69.         ret
  70.         .cfi_endproc
  71. .LFE0:
  72.         .size   main, .-main
  73.         .ident  "GCC: (GNU) 11.1.0"
  74.         .section        .note.GNU-stack,"",@progbits
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-6-10 09:36:31 | 显示全部楼层
这是对应的C语言代码
  1. #include <stdio.h>
  2. #include <ctype.h>

  3. int main(void) {
  4.     size_t letter = 0;
  5.     size_t number = 0;
  6.     size_t other = 0;
  7.     int ch;
  8.     while((ch = getchar()) != EOF) {
  9.         if(isalpha(ch)) ++letter;
  10.         else if(isdigit(ch)) ++number;
  11.         else ++other;
  12.     }
  13.     printf("letter: %lu, number: %lu, other: %lu\n", letter, number, other);
  14.     return 0;
  15. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-28 07:59

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表