1 #Program Description:
 2 #Author:Jeremy
 3 #Creation Date:2012/9/25 10:21
 4 #Revisions:
 5 #Date:     #Modified by:
 6 
 7 #寫一個組合語言程式,輸一整數 n, 印出 其絕對值。
 8 .section .data
 9    msg: .asciz "請輸入一整數:"
10    n:   .int 0
11    ifmt:.asciz "%d"
12    ofmt:.asciz "the abs value is %d"
13 .section .text
14     .globl _main
15 _main:
16     pushl $msg
17     call _printf 
18     addl $4, %esp
19 
20     pushl $n
21     pushl $ifmt
22     call _scanf    # scanf("%d",&n)
23     addl  $8, %esp
24    
25     cmp $0, n         # 數值一定要在前面
26     jge postive       # n >= 0 ?
27     movl $0, %eax
28     subl n, %eax      # subl 目標欄位必為register
29     pushl %eax
30     pushl $ofmt
31     call _printf
32     addl $4, %esp
33     jmp quit
34 postive:
35     pushl n     #printf("%d",n)
36     pushl $ofmt
37     call _printf
38     addl $4, %esp
39 quit:
40     pushl $0
41     call _exit
42     

相关文章:

  • 2021-11-27
  • 2022-12-23
  • 2021-11-06
  • 2021-12-01
  • 2022-02-20
  • 2022-12-23
  • 2021-12-18
  • 2021-12-23
猜你喜欢
  • 2021-05-28
  • 2021-11-23
  • 2021-12-03
  • 2021-09-08
  • 2022-02-08
  • 2022-12-23
  • 2021-11-09
相关资源
相似解决方案