MATHS
Assembly-Procedures.pptx

Assembly-Procedures.pptx - Assembly Language Procedures...

Info icon This preview shows pages 1–11. Sign up to view the full content.

Winter 2015 COMP 2130 Intro Computer Systems Computing Science Thompson Rivers University Assembly Language Procedures
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Objectives TRU-COMP2130 Introduction 2 Defining macros Defining Procedures Using stack
Image of page 2
Macro’s TRU-COMP2130 Introduction 3 The commands .macro and .endm allow you to define macros that generate assembly output It may allow to pass the parameters too separated by comma or space .macro sum a b movl \a, %eax mov \b, %ebx addl %ebx, %eax .endm
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Sample TRU-COMP2130 Introduction 4 The macros may be used as: .macro write str str_size movl $4, %eax movl $1, %ebx movl \str, %ecx movl \str_size, %edx int $0x80 .endm .macro writenum str movl $4, %eax movl $1, %ebx movl \str, %ecx movl $1, %edx int $0x80 .endm .macro read num movl $3, %eax movl $0, %ebx movl \num, %ecx movl $2, %edx int $0x80 .endm write $prompt_str1, $STR1_SIZE read $input1 write $prompt_str2, $STR2_SIZE read $input2 movl input1, %eax subl $0x30, %eax mov input2, %ebx subl $0x30, %ebx addl %ebx, %eax addl $0x30, %eax movl %eax, ans write $prompt_str3, $STR3_SIZE writenum $ans
Image of page 4
Procedures TRU-COMP2130 Introduction 5 The part of the program that is needed to be done many times is defined in the procedure Each procedure is identified by a name The procedure is defined as a label but after the execution of the procedure, the execution returns to the same place from where it has been called when ret (return) statement is executed The procedure may flow along multiple labels as well
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

syntax TRU-COMP2130 Introduction 6 Proc_name: statements statements ret
Image of page 6
example TRU-COMP2130 Introduction 7 .section .text .globl _start _start: write $prompt_str0, $STR0_SIZE read $num1, $2 read $num2, $2 movl num1, %eax subl $0x30, %eax movl num2, %ebx subl $0x30, %ebx addl %eax, %ebx movl %ebx, sum addl $0x30, sum write $prompt_str1, $STR1_SIZE writenam $num1, $1 writenam $num2, $1 writenam $sum, $1 call proc_1 exit: mov $1, %eax int $0x80 proc_1: write $prompt_str2, $STR2_SIZE ret
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

stack TRU-COMP2130 Introduction 8 Stack plays an important role when we use the procedures When a program starts executing, a certain contiguous section of memory is set aside for the program called the stack . The stack implementation has some special features, which are : The stack can only hold words or doublewords , not a byte. The stack grows in the reverse direction, i.e., toward the lower memory address The top of the stack points to the last item inserted in the stack; it points to the lower byte of the last word inserted. The stack pointer is the register that contains the top of the stack.
Image of page 8
Pointers TRU-COMP2130 Introduction 9 There are two pointers related to stack Stack pointer – ESP – Points to the top of the stack Stack base pointer – EBP – points to the base of the stack
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Stack Illustration TRU-COMP2130 Introduction 10 Figure 3.5 Illustration of stack operation
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '17
  • ANKITA
  • Math, Call stack, AMI, Carnegie Mello

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern