正在加载图片...
A.1 Introduction A-7 text .align .globl main main: subu $sp,$sp,32 SW sra. 20($sp) sd $a0.32($sp) SW $0 24($sp) $0. 28($sp)】 100p: lw $t6.28($sp) mul $t7,$t6,$t6 1w $t8,24($sp) addu $t9.$t8,$t7 SW $t9.24($sp) addu $t0.$t6,1 SW $t0.28($sD) ble $t0.100.100p la sa0.str lw $a1.24($sp) jal printf move $v0,$0 lw $ra,20($sp】 addu $sp,$sp,32 sra data .align 0 str: .asciiz "The sum from 0..100 is &d\n" FIGURE A.1.4 The same routine written in assembly language with labels,but no com- ments.The commands that start with periods are assembler directives (see pages A-47-A-49)..text indicates that succeeding lines contain instructions..data indicates that they contain data..al i gn n indicates that the items on the succeeding lines should be aligned on a 2"byte boundary.Hence,.al ign 2 means the next item should be on a word boundary..globl ma in declares that ma i n is a global sym- bol that should be visible to code stored in other files.Finally,.asci iz stores a null-terminated string in memory. When to Use Assembly Language The primary reason to program in assembly language,as opposed to an available high-level language,is that the speed or size of a program is critically important. For example,consider a computer that controls a piece of machinery,such as a car's brakes.A computer that is incorporated in another device,such as a car,is called an embedded computer.This type of computer needs to respond rapidly and predictably to events in the outside world.Because a compiler introduces uncer-A.1 Introduction A-7 When to Use Assembly Language The primary reason to program in assembly language, as opposed to an available high-level language, is that the speed or size of a program is critically important. For example, consider a computer that controls a piece of machinery, such as a car’s brakes. A computer that is incorporated in another device, such as a car, is called an embedded computer. This type of computer needs to respond rapidly and predictably to events in the outside world. Because a compiler introduces uncer- .text .align 2 .globl main main: subu $sp, $sp, 32 sw $ra, 20($sp) sd $a0, 32($sp) sw $0, 24($sp) sw $0, 28($sp) loop: lw $t6, 28($sp) mul $t7, $t6, $t6 lw $t8, 24($sp) addu $t9, $t8, $t7 sw $t9, 24($sp) addu $t0, $t6, 1 sw $t0, 28($sp) ble $t0, 100, loop la $a0, str lw $a1, 24($sp) jal printf move $v0, $0 lw $ra, 20($sp) addu $sp, $sp, 32 jr $ra .data .align 0 str: .asciiz "The sum from 0 .. 100 is %d\n" FIGURE A.1.4 The same routine written in assembly language with labels, but no com￾ments. The commands that start with periods are assembler directives (see pages A-47–A-49). .text indicates that succeeding lines contain instructions. .data indicates that they contain data. .align n indicates that the items on the succeeding lines should be aligned on a 2n byte boundary. Hence, .align 2 means the next item should be on a word boundary. .globl main declares that main is a global sym￾bol that should be visible to code stored in other files. Finally, .asciiz stores a null-terminated string in memory
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有