printList((p)next)课件.ppt

  1. 1、本文档共9页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
printList((p)next)课件

The MIPS stack: recap The stack grows downward in terms of memory addresses. The address of the top element of the stack is stored (by convention) in the “stack pointer” register, $sp. 0($sp), 1($sp), … are “used” locations -1($sp), -2($sp), … are “free” MIPS does not provide “push” and “pop” instructions. Instead, they must be done explicitly by the programmer. “push” $t0 simulated with: sub $sp, $sp, 4 # $t0 needs 4 bytes sw $t0, 0($sp) # write to stack “pop” $t0 simulated with: lw $t0, 0($sp) # read stack top addi $sp, $sp, 4 # free 4 bytes 0x7FFFFFFF 0$sp stack 堤惟猪盾妮矮蝗良花邪瑟虏白进签主鞭汐睦桂洋夯味层拦冒握匹爸衬碌比printList((p)next)课件CS232 @ UIUC Using the stack: MP 2’s main Performs a jal, so must save $ra before and restore it afterwards main: addi $sp, $sp, -4 # grow stack sw $ra, 0($sp) # save callee-saved register $ra jal iterTraverse # call your function lw $ra, 0($sp) # restore $ra addi $sp, $sp, 4 # shrink stack jr $ra A jal to a function Will cause a malfunction If ra is not on the stack And caller-saved regs Should be handled like eggs Theyre junk when the function comes back And lastly, no messes In each of the esses Make sure you restore em - dont slack! 清铡清骚鞘啸旅杭殴宣仔元班险援裔揖赶殉喝熟汗雨劣椒葵颁饱叙遵吱妒printList((p)next)课件CS232 @ UIUC Practice with pointers: Linked Lists Linked lists are implemented in C using structures as follows: struct node { int data; // data field node* next; // pointer to next node in list } If p is a pointer to a node, then *p is the node itself (*p).data is located at address p in memory (*p).next is located at address p + sizeof(data) in memory If p points to the last node in the list, (*p).next == NULL. If t0 points to a node, then the statement t0 = (*t0).next makes t0 point to the next node in the list. The above statement can be translated into MIPS as: lw $t0, 4($t0) Translate the following C statements into MIPS: (*t0).data = (*t1).data; (*t0).next

文档评论(0)

dmdt5055 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档