edx

堆和栈的区别 之 数据结构和内存

ε祈祈猫儿з 提交于 2019-12-04 14:46:50
数据结构的栈和堆 首先在数据结构上要知道堆栈,尽管我们这么称呼它,但实际上堆栈是两种数据结构:堆和栈。 堆和栈都是一种数据项按序排列的数据结构。 栈就像装数据的桶或箱子 我们先从大家比较熟悉的栈说起吧,它是一种具有后进先出性质的数据结构,也就是说后存放的先取,先存放的后取。 这就如同我们要取出放在箱子里面底下的东西(放入的比较早的物体),我们首先要移开压在它上面的物体(放入的比较晚的物体)。 堆像一棵倒过来的树 而堆就不同了,堆是一种经过排序的树形数据结构,每个结点都有一个值。 通常我们所说的堆的数据结构,是指二叉堆。 堆的特点是根结点的值最小(或最大),且根结点的两个子树也是一个堆。 由于堆的这个特性,常用来实现优先队列,堆的存取是随意,这就如同我们在图书馆的书架上取书,虽然书的摆放是有顺序的,但是我们想取任意一本时不必像栈一样,先取出前面所有的书,书架这种机制不同于箱子,我们可以直接取出我们想要的书。 内存分配中的栈和堆 先看百度百科中的内存堆栈介绍: 堆栈空间分配 栈(操作系统):由操作系统自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。 堆(操作系统): 一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回收,分配方式倒是类似于链表。 堆栈缓存方式 栈使用的是一级缓存, 他们通常都是被调用时处于存储空间中,调用完毕立即释放。

调用约定

旧巷老猫 提交于 2019-12-04 13:56:11
对于常见的指令集,在指令层面没有所谓的“函数”概念,只有“子程序”概念。子程序是存储在“主程序”之外的一段指令。子程序通过call指令调用,通过ret指令返回。子程序可以使用内存、堆栈和寄存器。通常主程序会传递参数给子程序,子程序将执行结果返回给主程序。这些参数和返回值如何传递,可以由开发者决定。不过如果程序中同时使用了高级语言和汇编语言,为了让编译器生成的汇编代码可以正确的汇编和连接,必须采用一个双方都遵守的传递参数和返回值的方法。这就是调用约定。换言之,调用约定是为了保证了不同函数可以正确汇编和链接而设计的,主程序和子程序之间传递数据的方式。 从上面的说明可以看到,调用约定涉及参数和返回值两部分。早期的高级语言(比如C)只有一个返回值,因此返回值的传递也较为简单。下表总结了几个平台上返回值的传递方法: | 平台 | 整型 | 结构体 | 浮点型 | | x86 | eax | eax | st(0) | | x86-64 | rax | rax | xmm0 | | ARM | R0 | R0 | R0 | | ARM64 | R0 | R0 | R0 | 调用约定中比较复杂的是参数传递方法,其中又以x86平台的调用约定种类繁多。 x86参数传递 在32位x86系统上,由于寄存器数量较少,参数主要通过栈传递,也产生了比较多的调用方式。MSVC和GCC支持的32位调用约定有: |

Operand type mismatch for idiv

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am currently writing a compiler which produces x86-32 code. However, I have a problem when trying to implement division. idivl %ecx, %ebx This code gives me the following error: Error: operand type mismatch for `idiv' Does anyone know why? The above lines are the only time idiv appears in my code. 回答1: According to my reference, IDIV divides the 64-bit integer EDX:EAX by the provided register's value. The idiv instruction divides the contents of the 64 bit integer EDX:EAX (constructed by viewing EDX as the most significant four bytes and

Assembler instruction: rdtsc

匿名 (未验证) 提交于 2019-12-03 08:56:10
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Could someone help me understand the assembler given in https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html It goes like this: uint64_t msr ; asm volatile ( "rdtsc\n\t" // Returns the time in EDX:EAX. "shl $32, %%rdx\n\t" // Shift the upper bits left. "or %%rdx, %0" // 'Or' in the lower bits. : "=a" ( msr ) : : "rdx" ); How is it different from: uint64_t msr ; asm volatile ( "rdtsc\n\t" : "=a" ( msr )); Why do we need shift and or operations and what does rdx at the end do? EDIT: added what is still unclear to the original

imul assembly instruction - one operand?

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using a run-time debugger. EAX: 0000 0023 EDX: 5555 5556 imul edx EAX: aaaa aac2 EDX: 0000 000b I am utterly confused, and can't figure out how this multiply is working. What's happening here? I notice in a similar question here that imul ebx ; result in EDX:EAX I don't understand the EDX:EAX notation though :/ 回答1: When the one-operand form of imul is passed a 32 bit argument (as in your case with EDX ) it effectively means EAX * EDX where both EAX and EDX are 32 bit registers. The product of two 32 bit values doesn't necessarily fit

Does a c/c++ compiler optimize constant divisions by power-of-two value into shifts?

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Question says it all. Does anyone know if the following... size_t div ( size_t value ) { const size_t x = 64 ; return value / x ; } ...is optimized into? size_t div ( size_t value ) { return value >> 6 ; } Do compilers do this? (My interest lies in GCC). Are there situations where it does and others where it doesn't? I would really like to know, because every time I write a division that could be optimized like this I spend some mental energy wondering about whether precious nothings of a second is wasted doing a division where a

asm in C “too many memory references for `mov'”

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've seen the post about the same error but i'm still get error : too many memory references for `mov' junk `hCPUIDmov buffer' after expression ... here's the code (mingw compiler / C::B) : #include iostream using namespace std; union aregister { int theint; unsigned bits[32]; }; union tonibbles { int integer; short parts[2]; }; void GetSerial() { int part1,part2,part3; aregister issupported; int buffer; __asm( "mov %eax, 01h" "CPUID" "mov buffer, edx" );//do the cpuid, move the edx (feature set register) to "buffer" issupported.theint =

Delphi Assembly Function Returning a Long String

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to learn inline assembly programming in Delphi, and to this end I have found this article highly helpful. Now I wish to write an assembly function returning a long string, specifically an AnsiString (for simplicity). I have written function myfunc: AnsiString; asm // eax = @result mov edx, 3 mov ecx, 1252 call System.@LStrSetLength mov [eax + 0], ord('A') mov [eax + 1], ord('B') mov [eax + 2], ord('C') end; Explanation: A function returning a string has an invisible var result: AnsiString (in this case) parameter, so, at the

understand cmpb and loops in assembly language

匿名 (未验证) 提交于 2019-12-03 00:56:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a function string_length that has the following assembly code 0x08048e90 <+0>: push %ebp 0x08048e91 <+1>: mov %esp,%ebp 0x08048e93 <+3>: mov 0x8(%ebp),%edx // assign whatever I declared into edx 0x08048e96 <+6>: mov $0x0,%eax // assign eax = 0 0x08048e9b <+11>: cmpb $0x0,(%edx) // compare edx to byte of 0 (null..?) 0x08048e9e <+14>: je 0x8048ea9 <string_length+25> // if equal, jump to +25 0x08048ea0 <+16>: add $0x1,%eax // else, add 1 to eax 0x08048ea3 <+19>: cmpb $0x0,(%edx,%eax,1) // compare byte 1*eax+edx with 0, 0x08048ea7 <+23>:

配置Pycharm4.5.4调试edX Devstack

雨燕双飞 提交于 2019-11-30 21:38:32
一、准备 1.在Ubuntn上利用vagrant+VirtualBox搭建好了edXDeveloper Stack,并能成功访问 2.在Ubuntu下安装好了Pycharm4.5.4并成功激活 二、配置 1.转换路径到本机/devstack/ 2.开启vagrant,输入命令: vagrant up 3.利用ssh连接vagrant,输入命令: vagrant ssh 4.给edxapp帐号一个密码,输入命令: sudo passwd edxapp (这里我输入的为edxapp) 5.开始配置Pycharm: 以上准备工作做完后,打开Pycharm,点击OpenDirectory, 选择本机/devstack/edx-platform,点击OK。 6.项目打开了,会一直在从源代码管理获取代码,所以先关了源代码管理。 方法:打开“File”->”Settings”->”VersionControl”然后在VCS下面选择none。 7.接下来配置Pycharm编译器: 依次打开File>Settings>ProjectInterpreter,在右侧ProjectInterpreter后面点配置图标AddRemoting,如下图 8.然后在ConfigureRemote Python Interpreter窗口内,选择SSHCredentials, Host 输入127.0.0.1,