Assembly and C Language

Source: Internet
Author: User

# File: Hello. C # include <stdio. h> # include <string. h> extern void printk (char); extern int max_p (INT, INT); char STR [] = "Hello world! \ N "; int main () {int I; for (I = 0; I <strlen (STR); I ++) printk (STR [I]); int max = max_p (18,200); printf ("% d \ n", max); printf ("% d \ n", max_p (10, 2 ));} # file: printk. s # include <stdio. h>. text. global printk. type printk, % function. global max_p.type max_p, % function. alignprintk :. fnstart extends FDSP !, {R0, r4-r7, LR}/* Register pressure stack */mov R1, r0mov r0, r1bl putcharreturn: ldmfdsp !, {R0, r4-r7, PC}/* LR save Pc value, input parameter: R0 ~ R3, return: R0 */. fnendmax_p:/*. fnstart */define fd sp !, {R4-r7, LR} CMP r0, r1bcs 1f/* cs as condition judgment, greater than or equal to 0 */mov r0, R11: ldmfd SP !, {R4-r7, PC}/*. fnend */# file: Build. Sh #! /Bin/Sharm-None-Linux-gnueabi-as printk. s-O printk. oarm-None-Linux-gnueabi-gcc-C hello. carm-None-Linux-gnueabi-gcc-static hello. O printk. o-O hello


# Include <stdio. h> memset:/* compute the offset to align the destination * offset = (4-(SRC & 3) & 3 =-Src & 3 */. fnstart. save {r0, r4-r7, LR} 127fd SP !, {R0, r4-r7, LR} RSB R3, R0, #0 ands R3, R3, #3 CMP R3, R2 movhi R3, R2/* splat R1 */mov R1, R1, LSL #24 Orr R1, R1, R1, LSR #8 Orr R1, R1, R1, LSR #16/* memset (void *, Int, INT) the second parameter only takes 8 lower bits of data, and the other bits use this bit to fill in the rush * // * if not aligned, the data is copied as this, for example, R3 = 3, r3 <post 31 CS flag is valid, and the maximum bit 1 OF R12 is valid */movs R12, R3, LSL #31 strcsb R1, [R0], #1/* can't use strh (alignment unknown) */strcsb R1, [R0], #1 strmib R1, [R0], #1 subs R2, R2, R3/* 1 ~ When three data entries exist, the function returns */ldmlsfd SP !, {R0, r4-r7, LR}/* ls flags indicate less than or equal to 0, return */bxls LR/* align the destination to a cache-line */mov R12, r1 mov LR, R1 mov R4, R1 mov R5, R1 mov R6, R1 mov R7, R1/* and R1 and R3 */RSB R3, R0, #0 ands R3, r3, # 0x1c beq aligned32/* 32 bytes aligned */CMP R3, r2/* calculate the number of bytes to be aligned with 32 bytes */andhi R3, R2, # 0x1c sub R2, R2, r3/* conditionnaly writes 0 to 7 words (length in R3) * // * a maximum of 28 Bytes: 16 + 8 + 4 */ Movs R3, R3, LSL #28 stmcsia R0 !, {R1, LR} stmcsia R0 !, {R1, LR} already miia R0 !, {R1, LR} movs R3, R3, LSL #2 strcs R1, [R0], #4 aligned32: subs R2, R2, #32/* count-= 32 */mov R3, R1 BMI 2f 1: subs R2, R2, #32 stmia R0 !, {R1, R3, R4, R5, R6, R7, R12, LR}/* store 32 bytes at a time */BHS 1B/* If the value is greater than or equal to 0, the cycle is as follows: do {r2 = R2-32; copy;} while (r2> = 0); */2: Add R2, R2, #32/* The Last 0 ~ 31 bytes */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.