C和汇编调用一例

  1. 现在实现下面功能:
  2. 实现字符串拷贝,当程序开始执行时,先有_start标号进入汇编文件,然后跳入main函数,将字符串拷贝函数的定义放在汇编文件中,在c中调用。
  3. 目录结构:
  4. image

 

strcpy.s

   1:  .global _start
   2:  .global mystrcpy
   3:   
   4:  _start:
   5:      B main
   6:  mystrcpy:
   7:      mov r2,#0
   8:      ldrb r2, [r0];
   9:      strb r2, [r1]
  10:      cmp r2, #0
  11:      beq rr
  12:      add r0, #1
  13:      add r1, #1
  14:      b mystrcpy
  15:  rr:
  16:     moveq pc,lr
  17:   

 

 

strcpy.c

 

   1:   
   2:  char *source = "pengdonglin137@163.com";
   3:   
   4:  char dest[20] ="";
   5:   
   6:  extern void mystrcpy(char *src, char *dst);
   7:   
   8:  int main(void){
   9:   
  10:      mystrcpy(source, dest);
  11:      while(1);
  12:      return 0;
  13:  }

Makefile

   1:  all:
   2:      arm-none-eabi-gcc -g -c strcpys.s -o mystrcpys.o        //
   3:      arm-none-eabi-gcc -g -c strcpyc.c -o mystrcpyc.o    
   4:      arm-none-eabi-ld -Ttext 0x20000 mystrcpys.o mystrcpyc.o -o mystrcpy.elf
   5:      arm-none-eabi-objdump -D mystrcpy.elf >p.dis   //反汇编
   6:  clean:
   7:      rm -rf *.o *.elf *.dis
   8:      

 

S5PC100.init

target remote 127.0.0.1:3333
monitor reset halt

 

下面是反汇编:

   1:   
   
  55:  Disassembly of section .comment:
  56:   
  57:  00000000 <.comment>:
  58:     0:    3a434347     bcc    10d0d24 <_stack+0x1050d24>
  59:     4:    4e472820     cdpmi    8, 4, cr2, cr7, cr0, {1}
  60:     8:    34202955     strtcc    r2, [r0], #-2389    ; 0x955
  61:     c:    322e362e     eorcc    r3, lr, #48234496    ; 0x2e00000
  62:      ...
  63:   
  64:  Disassembly of section .debug_aranges:
  65:   
  66:  00000000 <.debug_aranges>:
  67:     0:    0000001c     andeq    r0, r0, ip, lsl r0
  68:     4:    00000002     andeq    r0, r0, r2
  69:     8:    00040000     andeq    r0, r4, r0
  70:     c:    00000000     andeq    r0, r0, r0
  71:    10:    00020000     andeq    r0, r2, r0
  72:    14:    00000028     andeq    r0, r0, r8, lsr #32
  73:      ...
  74:    20:    0000001c     andeq    r0, r0, ip, lsl r0
  75:    24:    004d0002     subeq    r0, sp, r2
  76:    28:    00040000     andeq    r0, r4, r0
  77:    2c:    00000000     andeq    r0, r0, r0
  78:    30:    00020028     andeq    r0, r2, r8, lsr #32
  79:    34:    00000028     andeq    r0, r0, r8, lsr #32
  80:      ...
  81:   
  82:  Disassembly of section .debug_info:
  83:   
  84:  00000000 <.debug_info>:
  85:     0:    00000049     andeq    r0, r0, r9, asr #32
  86:     4:    00000002     andeq    r0, r0, r2
  87:     8:    01040000     mrseq    r0, (UNDEF: 4)
  88:     c:    00000000     andeq    r0, r0, r0
  89:    10:    00020000     andeq    r0, r2, r0
  90:    14:    00020028     andeq    r0, r2, r8, lsr #32
  91:    18:    63727473     cmnvs    r2, #1929379840    ; 0x73000000
  92:    1c:    2e737970     mrccs    9, 3, r7, cr3, cr0, {3}
  93:    20:    3a440073     bcc    11001f4 <_stack+0x10801f4>
  94:    24:    6c63655c     cfstr64vs    mvdx6, [r3], #-368    ; 0xfffffe90
  95:    28:    65737069     ldrbvs    r7, [r3, #-105]!    ; 0x69
  96:    2c:    6f72705f     svcvs    0x0072705f
  97:    30:    7463656a     strbtvc    r6, [r3], #-1386    ; 0x56a
  98:    34:    796d5c73     stmdbvc    sp!, {r0, r1, r4, r5, r6, sl, fp, ip, lr}^
  99:    38:    63727473     cmnvs    r2, #1929379840    ; 0x73000000
 100:    3c:    47007970     smlsdxmi    r0, r0, r9, r7
 101:    40:    4120554e     teqmi    r0, lr, asr #10
 102:    44:    2e322053     mrccs    0, 1, r2, cr2, cr3, {2}
 103:    48:    01003132     tsteq    r0, r2, lsr r1
 104:    4c:    0000a480     andeq    sl, r0, r0, lsl #9
 105:    50:    14000200     strne    r0, [r0], #-512    ; 0x200
 106:    54:    04000000     streq    r0, [r0]
 107:    58:    00000001     andeq    r0, r0, r1
 108:    5c:    00250100     eoreq    r0, r5, r0, lsl #2
 109:    60:    002f0000     eoreq    r0, pc, r0
 110:    64:    00280000     eoreq    r0, r8, r0
 111:    68:    00500002     subseq    r0, r0, r2
 112:    6c:    00400002     subeq    r0, r0, r2
 113:    70:    01020000     mrseq    r0, (UNDEF: 2)
 114:    74:    0000004c     andeq    r0, r0, ip, asr #32
 115:    78:    3e010801     cdpcc    8, 0, cr0, cr1, cr1, {0}
 116:    7c:    28000000     stmdacs    r0, {}    ; <UNPREDICTABLE>
 117:    80:    50000200     andpl    r0, r0, r0, lsl #4
 118:    84:    00000200     andeq    r0, r0, r0, lsl #4
 119:    88:    03000000     movweq    r0, #0
 120:    8c:    6e690504     cdpvs    5, 6, cr0, cr9, cr4, {0}
 121:    90:    0c040074     stceq    0, cr0, [r4], {116}    ; 0x74
 122:    94:    01000000     mrseq    r0, (UNDEF: 0)
 123:    98:    00005202     andeq    r5, r0, r2, lsl #4
 124:    9c:    05010100     streq    r0, [r1, #-256]    ; 0x100
 125:    a0:    00005804     andeq    r5, r0, r4, lsl #16
 126:    a4:    08010600     stmdaeq    r1, {r9, sl}
 127:    a8:    00000051     andeq    r0, r0, r1, asr r0
 128:    ac:    00005807     andeq    r5, r0, r7, lsl #16
 129:    b0:    00006f00     andeq    r6, r0, r0, lsl #30
 130:    b4:    006f0800     rsbeq    r0, pc, r0, lsl #16
 131:    b8:    00130000     andseq    r0, r3, r0
 132:    bc:    13070406     movwne    r0, #29702    ; 0x7406
 133:    c0:    04000000     streq    r0, [r0]
 134:    c4:    00000020     andeq    r0, r0, r0, lsr #32
 135:    c8:    005f0401     subseq    r0, pc, r1, lsl #8
 136:    cc:    01010000     mrseq    r0, (UNDEF: 1)
 137:    d0:    00000c09     andeq    r0, r0, r9, lsl #24
 138:    d4:    52020100     andpl    r0, r2, #0
 139:    d8:    01000000     mrseq    r0, (UNDEF: 0)
 140:    dc:    80680305     rsbhi    r0, r8, r5, lsl #6
 141:    e0:    20090002     andcs    r0, r9, r2
 142:    e4:    01000000     mrseq    r0, (UNDEF: 0)
 143:    e8:    00005f04     andeq    r5, r0, r4, lsl #30
 144:    ec:    03050100     movweq    r0, #20736    ; 0x5100
 145:    f0:    0002806c     andeq    r8, r2, ip, rrx
 146:      ...
 147:   
 148:  Disassembly of section .debug_abbrev:
 149:   
 150:  00000000 <.debug_abbrev>:
 151:     0:    10001101     andne    r1, r0, r1, lsl #2
 152:     4:    12011106     andne    r1, r1, #-2147483647    ; 0x80000001
 153:     8:    1b080301     blne    200c14 <_stack+0x180c14>
 154:     c:    13082508     movwne    r2, #34056    ; 0x8508
 155:    10:    00000005     andeq    r0, r0, r5
 156:    14:    25011101     strcs    r1, [r1, #-257]    ; 0x101
 157:    18:    030b130e     movweq    r1, #45838    ; 0xb30e
 158:    1c:    110e1b0e     tstne    lr, lr, lsl #22
 159:    20:    10011201     andne    r1, r1, r1, lsl #4
 160:    24:    02000006     andeq    r0, r0, #6
 161:    28:    0c3f002e     ldceq    0, cr0, [pc], #-184    ; ffffff78 <_stack+0xfff7ff78>
 162:    2c:    0b3a0e03     bleq    e83840 <_stack+0xe03840>
 163:    30:    0c270b3b     stceq    11, cr0, [r7], #-236    ; 0xffffff14
 164:    34:    01111349     tsteq    r1, r9, asr #6
 165:    38:    06400112             ; <UNDEFINED> instruction: 0x06400112
 166:    3c:    24030000     strcs    r0, [r3]
 167:    40:    3e0b0b00     vmlacc.f64    d0, d11, d0
 168:    44:    0008030b     andeq    r0, r8, fp, lsl #6
 169:    48:    00340400     eorseq    r0, r4, r0, lsl #8
 170:    4c:    0b3a0e03     bleq    e83860 <_stack+0xe03860>
 171:    50:    13490b3b     movtne    r0, #39739    ; 0x9b3b
 172:    54:    0c3c0c3f     ldceq    12, cr0, [ip], #-252    ; 0xffffff04
 173:    58:    0f050000     svceq    0x00050000
 174:    5c:    490b0b00     stmdbmi    fp, {r8, r9, fp}
 175:    60:    06000013             ; <UNDEFINED> instruction: 0x06000013
 176:    64:    0b0b0024     bleq    2c00fc <_stack+0x2400fc>
 177:    68:    0e030b3e     vmoveq.16    d3[0], r0
 178:    6c:    01070000     mrseq    r0, (UNDEF: 7)
 179:    70:    01134901     tsteq    r3, r1, lsl #18
 180:    74:    08000013     stmdaeq    r0, {r0, r1, r4}
 181:    78:    13490021     movtne    r0, #36897    ; 0x9021
 182:    7c:    00000b2f     andeq    r0, r0, pc, lsr #22
 183:    80:    03003409     movweq    r3, #1033    ; 0x409
 184:    84:    3b0b3a0e     blcc    2ce8c4 <_stack+0x24e8c4>
 185:    88:    3f13490b     svccc    0x0013490b
 186:    8c:    000a020c     andeq    r0, sl, ip, lsl #4
 187:      ...
 188:   
 189:  Disassembly of section .debug_line:
 190:   
 191:  00000000 <.debug_line>:
 192:     0:    0000003c     andeq    r0, r0, ip, lsr r0
 193:     4:    00200002     eoreq    r0, r0, r2
 194:     8:    01020000     mrseq    r0, (UNDEF: 2)
 195:     c:    000d0efb     strdeq    r0, [sp], -fp
 196:    10:    01010101     tsteq    r1, r1, lsl #2
 197:    14:    01000000     mrseq    r0, (UNDEF: 0)
 198:    18:    00010000     andeq    r0, r1, r0
 199:    1c:    63727473     cmnvs    r2, #1929379840    ; 0x73000000
 200:    20:    2e737970     mrccs    9, 3, r7, cr3, cr0, {3}
 201:    24:    00000073     andeq    r0, r0, r3, ror r0
 202:    28:    05000000     streq    r0, [r0]
 203:    2c:    02000002     andeq    r0, r0, #2
 204:    30:    2f301600     svccs    0x00301600
 205:    34:    2f2f2f2f     svccs    0x002f2f2f
 206:    38:    02302f2f     eorseq    r2, r0, #188    ; 0xbc
 207:    3c:    01010002     tsteq    r1, r2
 208:    40:    00000039     andeq    r0, r0, r9, lsr r0
 209:    44:    00200002     eoreq    r0, r0, r2
 210:    48:    01020000     mrseq    r0, (UNDEF: 2)
 211:    4c:    000d0efb     strdeq    r0, [sp], -fp
 212:    50:    01010101     tsteq    r1, r1, lsl #2
 213:    54:    01000000     mrseq    r0, (UNDEF: 0)
 214:    58:    00010000     andeq    r0, r1, r0
 215:    5c:    63727473     cmnvs    r2, #1929379840    ; 0x73000000
 216:    60:    2e637970     mcrcs    9, 3, r7, cr3, cr0, {3}
 217:    64:    00000063     andeq    r0, r0, r3, rrx
 218:    68:    05000000     streq    r0, [r0]
 219:    6c:    02002802     andeq    r2, r0, #131072    ; 0x20000
 220:    70:    004c1900     subeq    r1, ip, r0, lsl #18
 221:    74:    9f010402     svcls    0x00010402
 222:    78:    01000602     tsteq    r0, r2, lsl #12
 223:    7c:    Address 0x0000007c is out of bounds.
 224:   
 225:   
 226:  Disassembly of section .debug_frame:
 227:   
 228:  00000000 <.debug_frame>:
 229:     0:    0000000c     andeq    r0, r0, ip
 230:     4:    ffffffff             ; <UNDEFINED> instruction: 0xffffffff
 231:     8:    7c020001     stcvc    0, cr0, [r2], {1}
 232:     c:    000d0c0e     andeq    r0, sp, lr, lsl #24
 233:    10:    00000018     andeq    r0, r0, r8, lsl r0
 234:    14:    00000000     andeq    r0, r0, r0
 235:    18:    00020028     andeq    r0, r2, r8, lsr #32
 236:    1c:    00000028     andeq    r0, r0, r8, lsr #32
 237:    20:    8e080e42     cdphi    14, 0, cr0, cr8, cr2, {2}
 238:    24:    42028b01     andmi    r8, r2, #1024    ; 0x400
 239:    28:    00040b0c     andeq    r0, r4, ip, lsl #22
 240:   
 241:  Disassembly of section .debug_str:
 242:   
 243:  00000000 <.debug_str>:
 244:     0:    20554e47     subscs    r4, r5, r7, asr #28
 245:     4:    2e342043     cdpcs    0, 3, cr2, cr4, cr3, {2}
 246:     8:    00322e36     eorseq    r2, r2, r6, lsr lr
 247:     c:    72756f73     rsbsvc    r6, r5, #460    ; 0x1cc
 248:    10:    75006563     strvc    r6, [r0, #-1379]    ; 0x563
 249:    14:    6769736e     strbvs    r7, [r9, -lr, ror #6]!
 250:    18:    2064656e     rsbcs    r6, r4, lr, ror #10
 251:    1c:    00746e69     rsbseq    r6, r4, r9, ror #28
 252:    20:    74736564     ldrbtvc    r6, [r3], #-1380    ; 0x564
 253:    24:    72747300     rsbsvc    r7, r4, #0
 254:    28:    63797063     cmnvs    r9, #99    ; 0x63
 255:    2c:    4400632e     strmi    r6, [r0], #-814    ; 0x32e
 256:    30:    63655c3a     cmnvs    r5, #14848    ; 0x3a00
 257:    34:    7370696c     cmnvc    r0, #1769472    ; 0x1b0000
 258:    38:    72705f65     rsbsvc    r5, r0, #404    ; 0x194
 259:    3c:    63656a6f     cmnvs    r5, #454656    ; 0x6f000
 260:    40:    6d5c7374     ldclvs    3, cr7, [ip, #-464]    ; 0xfffffe30
 261:    44:    72747379     rsbsvc    r7, r4, #-469762047    ; 0xe4000001
 262:    48:    00797063     rsbseq    r7, r9, r3, rrx
 263:    4c:    6e69616d     powvsez    f6, f1, #5.0
 264:    50:    61686300     cmnvs    r8, r0, lsl #6
 265:    54:    Address 0x00000054 is out of bounds.
 266:   
 267:   
 268:  Disassembly of section .debug_loc:
 269:   
 270:  00000000 <.debug_loc>:
 271:     0:    00000000     andeq    r0, r0, r0
 272:     4:    00000004     andeq    r0, r0, r4
 273:     8:    007d0002     rsbseq    r0, sp, r2
 274:     c:    00000004     andeq    r0, r0, r4
 275:    10:    00000008     andeq    r0, r0, r8
 276:    14:    087d0002     ldmdaeq    sp!, {r1}^
 277:    18:    00000008     andeq    r0, r0, r8
 278:    1c:    00000028     andeq    r0, r0, r8, lsr #32
 279:    20:    047b0002     ldrbteq    r0, [fp], #-2
 280:      ...
 281:   
 282:  Disassembly of section .ARM.attributes:
 283:   
 284:  00000000 <_stack-0x80000>:
 285:     0:    00002d41     andeq    r2, r0, r1, asr #26
 286:     4:    61656100     cmnvs    r5, r0, lsl #2
 287:     8:    01006962     tsteq    r0, r2, ror #18
 288:     c:    00000023     andeq    r0, r0, r3, lsr #32
 289:    10:    4d524105     ldfmie    f4, [r2, #-20]    ; 0xffffffec
 290:    14:    4d445437     cfstrdmi    mvd5, [r4, #-220]    ; 0xffffff24
 291:    18:    02060049     andeq    r0, r6, #73    ; 0x49
 292:    1c:    01090108     tsteq    r9, r8, lsl #2
 293:    20:    01140412     tsteq    r4, r2, lsl r4
 294:    24:    03170115     tsteq    r7, #1073741829    ; 0x40000005
 295:    28:    011a0118     tsteq    sl, r8, lsl r1
 296:    2c:    Address 0x0000002c is out of bounds.
 297:   

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/pengdonglin137/archive/2013/04/18/3029259.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/408940.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

机器学习算法总结--朴素贝叶斯

这次需要总结的是朴素贝叶斯算法&#xff0c;参考文章&#xff1a; 《统计学习方法》机器学习常见算法个人总结&#xff08;面试用&#xff09;朴素贝叶斯理论推导与三种常见模型朴素贝叶斯的三个常用模型&#xff1a;高斯、多项式、伯努利 简介 朴素贝叶斯是基于贝叶斯定理与…

行添加DataGridView导出Excel的数据表格

最近研究行添加&#xff0c;稍微总结一下&#xff0c;以后继续补充&#xff1a; 将DataGridView中的据数导出为Excel的据数表格&#xff0c;方法有很多种&#xff0c;面下供提一种本人认为是一个好解理&#xff0c;较单简的方法。步调如下&#xff1a; 1、添加引用 2、编写码代…

机器学习算法总结--K近邻

参考文章&#xff1a; 《统计学习方法》机器学习常见算法个人总结&#xff08;面试用&#xff09;机器学习系列(9)_机器学习算法一览&#xff08;附Python和R代码&#xff09; 简介 k近邻&#xff08;KNN)是一种基本分类与回归方法。 其思路如下&#xff1a;给一个训练数据集…

机器学习算法总结--提升方法

参考自&#xff1a; 《统计学习方法》浅谈机器学习基础&#xff08;上&#xff09;Ensemble learning:Bagging,Random Forest,Boosting 简介 提升方法(boosting)是一种常用的统计学习方法&#xff0c;在分类问题中&#xff0c;它通过改变训练样本的权重&#xff0c;学习多个分…

matlab画x的1 3次方,如何用Matlab画出f(x)=f(x-1)+2的x次方*3的图像

如何用Matlab画出f(x)f(x-1)2的x次方*3的图像以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;如何用Matlab画出f(x)f(x-1)2的x次方*3的图像你要画的范围假设是0到10Fzeros(1,10);F(1)1;要有初…

机器学习算法总结--GBDT

参考如下 机器学习&#xff08;四&#xff09;— 从gbdt到xgboost机器学习常见算法个人总结&#xff08;面试用&#xff09;xgboost入门与实战&#xff08;原理篇&#xff09; 简介 GBDT是一个基于迭代累加的决策树算法&#xff0c;它通过构造一组弱的学习器&#xff08;树&a…

机器学习算法总结--EM算法

参考自 《统计学习方法》机器学习常见算法个人总结&#xff08;面试用&#xff09;从最大似然到EM算法浅解&#xff08;EM算法&#xff09;The EM Algorithm 简介 EM算法&#xff0c;即期望极大算法&#xff0c;用于含有隐变量的概率模型的极大似然估计或极大后验概率估计&am…

CPP第四版第四章:创建动态数组

数组类型的变量有三个重要限制&#xff1a; 数组长度固定不变 在编译时必须知道其长度 数组只在定义它的块语句内存在 每一个程序在执行时都占用一块可用的内存空间&#xff0c;用于存放动态分配的对象&#xff0c;此内存空间称为程序的自由存储区或堆…

(转)非极大抑制(Non-Maximum Suppression)

转载自非极大抑制&#xff08;Non-Maximum Suppression&#xff09;。 参考文章&#xff1a; 1. Non-Maximum Suppression for Object Detection in Python 2. NMS非极大值抑制 最近在做人脸识别的项目&#xff0c;其中在人脸检测算法中MTCNN算法是用到了NMS算法来筛选候选…