Linux下組合語言------計算n的階乘

來源:互聯網
上載者:User

標籤:組合語言   linux   

用進階語言比如C語言寫個階乘很簡單,那現在就來熟悉下Linux使用AT&T彙編格式寫一個程式來計算階乘吧

寫法一是 使用跳轉指令實現,寫法二是使用函數來實現

約定:本程式沒有將結果列印在標準輸出上。需要使用GDB調試查看

寫法一
#as filename.s -o filename.o#ld filename.o -o filename # gdb filename.section .data.section .text.globl _start_start:movl $1, %eax #result = 1movl $6, %ecx # n = 5cmpl $1, %ecxjle .loop_exit.start_loop:imull %ecx, %eaxsubl  $1, %ecxcmpl $1, %ecxjge .start_loopmovl %eax, %ebxmovl $1, %eaxint $0x80 .loop_exit:movl $1, %eaxint $0x80
--------------------函數寫法待更新-------------------------

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

Linux下組合語言------計算n的階乘

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.