【汇编语言】汇编语言实现if while for,以及编写冒泡排序

您所在的位置:网站首页 汇编语言无限循环 【汇编语言】汇编语言实现if while for,以及编写冒泡排序

【汇编语言】汇编语言实现if while for,以及编写冒泡排序

2023-08-28 18:11| 来源: 网络整理| 查看: 265

一、if的实现

  c语言代码:

if (ax == bx) { /* codes */ } if (ax) { /* codes */ } if (ax /* codes1 */ } else { /* codes2 */ }

  汇编代码

cmp ax, 0 je s: ;codes1; jmp e s: ;codes2; e: 三、if…else if…else的实现

  c语言代码

if (ax /* code2 */ } else if (ax /* code4 */ } cmp ax, 60 jge s0 ;codes1; jmp e s0: cmp ax, 70 jge s1 ;codes2; jmp e s1: cmp ax, 80 jge s2 ;codes3; jmp e s2: ;codes4; e: 三、while的实现

  c语言代码:

while (ax) { /* codes */ } while (ax) { if (bx) { /* codes */ break; } } while (ax) { if (bx) { /* codes */ continue; } } while (ax) { if (bx) { /* codes1 */ } else { /* codes2 */ } }

  汇编语言代码

s: cmp ax, 0 jne e ;codes; jmp s e: s0: cmp ax, 0 jne e0 cmp bx, 0 je e1 ;codes; jmp e0 e1: jmp s0 e0: s0: cmp ax, 0 jne e0 cmp bx, 0 je e1 ;codes; jmp s0 e1: jmp s0 e0 s0: cmp ax, 0 jne e0 cmp bx, 0 je s1 ;codes; jmp e1 s1: ;codes; e1: jmp s0 e0: 四、for的实现

  ·c语言代码

int i; for(i = 0; i /* codes */ i++; }

  相应的汇编代码:

mov si, 0 s: cmp si, ax jge e ;codes; inc si jmp s e: 五、实例

  我们来敲一个冒泡排序吧。

  先写c语言版本的

#include int main() { int n = 5; int a[n] = {1, 4, 3, 5, 2}; int i, j; for(i = 0; i if (a[i] > a[j]) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } } } for (i = 0; i


【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3