简体   繁体   English

程序的机器代码指令

[英]machine code instructions for a program

how do we put the program instruction c = ab; 我们如何把程序指令c = ab; in machine code instructions? 在机器代码说明中? i've been provided with op-codes, memory address for a=80, b=81, c=82 and program counter = 30 hex. 我已经提供了操作码,内存地址为a = 80,b = 81,c = 82,程序计数器为30十六进制。 instructions are 16 bits long with 4bit op-code, 4bit for register and 16 bit for memory address. 指令为16位长,带有4位操作码,4位用于寄存器,16位用于存储器地址。

i just need to know the formal way how it is started. 我只需要知道正式开始的正式方式即可。 this is because i really don't understand what my lecturer teaches. 这是因为我真的不明白我的讲师教什么。 if i can get a clear direction, then i am confident i can do this without the help of my lecturer. 如果我能找到一个明确的方向,那么我有信心可以在没有老师帮助的情况下做到这一点。

The mnemonics would look something like this: 助记符如下所示:

mov eax, [a] ; move 4 bytes starting at address a to the eax register
sub eax, [b] ; subtract 4 bytes starting at memory address b from the eax register
mov [c], eax ; move the contents of the eax register to the memory address of c

You substitute in your opcodes for the operations ( mov , sub ), the register address for ( eax ), memory addresses for ( a , b , c ) and the and then the result are actual machine instructions. 您可以用操作码代替操作( movsub ),( eax )的寄存器地址,( abc )的内存地址,然后是实际的机器指令。 I'm assuming here your numbers are 32 bit integers, so I'm using the eax register which is 32 bits long for an x86 processor, but the specifics of which register you use is arbitrary, as long as it's big enough to hold your number. 我在这里假设您的数字是32位整数,所以我使用的x处理器的eax寄存器长32位,但是您使用的哪个寄存器的细节是任意的,只要它足以容纳您的数。 The mov instruction will read as many bytes as the register can hold starting at the memory address provided. mov指令将从提供的内存地址开始读取寄存器可容纳的尽可能多的字节。

You don't explicitly need to do anything about the program counter for this example, the CPU increments the program counter as it executes each instruction. 在此示例中,您无需明确地对程序计数器做任何事情,CPU在执行每条指令时都会递增程序计数器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM