⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sub5.asm

📁 PC Assembly Tutorial running the code in the tutorial, you need get the appropriate zip file of thi
💻 ASM
字号:
;; file: sub5.asm; Subprogram to C interfacing example%include "asm_io.inc"; subroutine _calc_sum; finds the sum of the integers 1 through n; Parameters:;   n    - what to sum up to (at [ebp + 8]);   sump - pointer to int to store sum into (at [ebp + 12]); pseudo C code:; void calc_sum( int n, int * sump ); {;   int i, sum = 0;;   for( i=1; i <= n; i++ );     sum += i;;   *sump = sum;; };; To assemble:; DJGPP:   nasm -f coff sub5.asm; Borland: nasm -f obj  sub5.asmsegment .text        global  _calc_sum;; local variable:;   sum at [ebp-4]_calc_sum:        enter   4,0               ; allocate room for sum on stack        push    ebx               ; IMPORTANT!        mov     dword [ebp-4],0   ; sum = 0        dump_stack 1, 2, 4        ; print out stack from ebp-8 to ebp+16        mov     ecx, 1            ; ecx is i in pseudocodefor_loop:        cmp     ecx, [ebp+8]      ; cmp i and n        jnle    end_for           ; if not i <= n, quit        add     [ebp-4], ecx      ; sum += i        inc     ecx        jmp     short for_loopend_for:        mov     ebx, [ebp+12]     ; ebx = sump        mov     eax, [ebp-4]      ; eax = sum        mov     [ebx], eax        pop     ebx               ; restore ebx        leave        ret

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -