NYU CSCI-UA 0201 - RET Instructions and the Stack (10 pages)

Previewing pages 1, 2, 3 of 10 page document View the full content.
View Full Document

RET Instructions and the Stack



Previewing pages 1, 2, 3 of actual document.

View the full content.
View Full Document
View Full Document

RET Instructions and the Stack

11 views


Pages:
10
School:
New York University
Course:
Csci-Ua 0201 - Computer Systems Organization
Computer Systems Organization Documents

Unformatted text preview:

The CALL RET Instructions and the Stack In the previous chapter we explained most of the lines of the assembler file that is generated by the compiler for a C file with one important exception which is the ret instruction at the end of the function Let s just review a simple example unsigned a 6 void f a a a void g f f The corresponding assembler file is file x c intel syntax globl a data align 4 a long 6 text globl f def f scl 2 type f mov eax DWORD PTR a add DWORD PTR a eax ret globl g def g scl 2 type g call f call f ret 32 endef 32 endef Most of the lines in this file are familiar from the previous chapter The file directive gives the name of the original source file for informational purposes The intel sytax line tells the assembler we are using Intel rather than AT T syntax The globl lines are used to tell the assembler that the corresponding symbols should be marked as globally accessible from other files The data directive marks the start of the data in the program and text marks the start of the program The align directive makes sure that the variable is on a 4 byte boundary for efficiency purposes The long directive actually generates four bytes of data containing the specified initial value The label lines such as a associate assembler labels with specific addresses in memory The mov instruction loads a word into a register The add instruction adds the contents of a register to a word in memory The previous paragraph identifies every line in the assembler output see previous chapter if you need to consult the more detailed descriptions with two notable exceptions the call instruction and the ret instruction In general terms we know what these do The call instruction clearly transfers control to another procedure and the ret instruction returns to the instruction following the call For rough understanding of what the assembler means this is an adequate level of explanation That s even a sufficient explanation for writing assembler yourself You can just



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view RET Instructions and the Stack and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view RET Instructions and the Stack and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?