lect13 - Introduction to Computer Systems Lecture 13...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Computer Systems Lecture 13 Assembly Language Jan Plane & Pete Keleher {jplane, keleher}@cs.umd.edu Administrivia Still reading Bryant and OHallaron Chapter 3 (IA-32 instruction set architecture) and 4.1 (Y86 subset) Project 3 48-hour extension to Sunday night. 2 Last Time: Branch example 1 Assembler output: 0x000: f208 | rdint %eax 0x002: 308700000000 | irmovl $0,%edi # consistent zero 0x008: 308600000000 | irmovl $0,%esi # sum = 0 0x00e: 6070 | addl %edi,%eax 0x010: 7320000000 | je EndLoop | 0x015: 6006 | Loop: addl %eax,%esi # sum += n 0x017: f208 | rdint %eax 0x019: 6070 | addl %edi,%eax 0x01b: 7415000000 | jne Loop | 0x020: f368 | EndLoop: wrint %esi 0x022: 30830a000000 | irmovl $10,%ebx 0x028: f138 | wrch %ebx 0x02a: 10 | halt Simulator output: $ echo 1 4 9 16 25 0 | yis io.yo 55 Stopped in 29 steps at PC = 0x2b. Exception 'HLT', CC Z=1 S=0 O=0 ... 3 Branch example 2 Assembler output: 0x000: 308003000000 | irmovl $3,%eax # a = 3 0x006: 308304000000 | irmovl $4,%ebx # b = 4 0x00c: 2006 | rrmovl %eax,%esi # s = a 0x00e: 6136 | subl %ebx,%esi # s = s - b 0x010: 751c000000 | jge Else # if s >= 0 jump | 0x015: f308 | wrint %eax # printf("%d", a) 0x017: 701e000000 | jmp Endif # jump | 0x01c: f338 | Else: wrint %ebx # printf("%d", b) | 0x01e: 30860a000000 | Endif: irmovl $10,%esi 0x024: f168 | wrch %esi # printf("\n") 0x026: 10 | halt Simulator output: 3 Stopped in 10 steps at PC = 0x27. Exception 'HLT', CC Z=0 S=1 O=0 ... 4 Other Y86 instructions Instruction Effect Description halt Ends program Program halt pushl R Reg[ %esp ] Reg[ %esp ] - 4; Mem[Reg[ %esp ]] Reg[R] Push on to stack popl R Reg[R] Mem[Reg[ %esp ]] ; Reg[ %esp ] Reg[ %esp ] + 4 Pop off of stack 5 Without a halt instruction, the simulator will attempt to read in possibly invalid instructions pushl and popl provide quick ways to work with the program stack what would you have to do if you didn't have access to these? why shouldn't you use %esp as a general purpose register? Assembler directives These can be used to set up memory in various places in the address space .pos can put sections of code in different places in memory .align should be used before setting up a static variable .long can be used to initialize a static variable 6 Directive Effect .pos number Subsequent lines of code start at address number .align number Align the next line to a number-byte boundary .long number Put number at the current address in memory Translating loops What about C code like this? do { ... } while (condition); This can be translated simply: Loop: ... # begin loop body # evaluate condition je Loop # jump back if true Note that you can use whatever jump instruction/condition is appropriate 7 Translating while loops while loops are a bit different; but these can be written as do-while loops, with a little modification while (condition) do_something(); if (condition) { do { do_something(); } while(condition); } 8 if (! condition) goto EndWhile; do { do_something(); } while (condition); EndWhile:...
View Full Document

This note was uploaded on 01/13/2012 for the course CMSC 216 taught by Professor Plane during the Spring '11 term at Maryland.

Page1 / 51

lect13 - Introduction to Computer Systems Lecture 13...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online