0

I am looking for an opinion.

I got a fillup the gaps type question in computer architecture for the y86 architecture.

movq [a], [b]
subq [c], [d]

Possible answers are

REG
$8
%rsp
8(%rsp)
-8(%rsp)
%rsp

Can we solve it as it is when they are not providing any C code / skeleton program with these move and subtract instructions?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Encipher
  • 1,370
  • 1
  • 14
  • 31
  • 4
    What is the question? All the listed 'possible answers' are *legal* for any (but not all) of the 4 operands. Whether they make sense or not is another question -- many combos are clearly nonsense but several might make sense. – Chris Dodd Feb 03 '22 at 00:53
  • 2
    y86 doesn't have a `mov` mnemonic in the first place, it has `rrmov` / `rmmov` and `mrmov` / `irmov` which constrain what the operands can be. Unless you're using a different assembler that infers the mov type from the operands? As for `sub`, I forget if y86 allows memory operands for instructions other than `mov` the way x86 does, or if it's a load/store machine where only `mov` can access memory. – Peter Cordes Feb 03 '22 at 01:49
  • Yes, it can probably be solved without seeing any C code. Except that the question appear quite underspecified/ambiguous, and also with typos/errors. Would not expect C code would clear those up, but who knows.. – Erik Eidt Feb 03 '22 at 01:54
  • @ChrisDodd Yes I also found all the listed possible answer are legal. Like, if I write `movq $8 %rsp` means a movq instruction which sets the value of the 64-bit %rsp register to the immediate value 8. So, if I procced like that what would should I write subq [c] [d] – Encipher Feb 03 '22 at 02:30
  • @ErikEidt can you please explain which are typos? – Encipher Feb 03 '22 at 02:31
  • 1
    Is the list of operands supposed to be sampled without replacement? So the fact that `%rsp` appears twice means you can use it twice, others can be used at most once? There are certainly multiple valid combinations of operands, but most of them non-useful. (Like subtracting the stack pointer from some qword of stack memory, or worse loading a new stack pointer or setting it to 8.) – Peter Cordes Feb 03 '22 at 03:09
  • @Peter Cordes Yes we can use %rsp twice. I have suggested one combination in my previous answer. What do you think will be the valid combinations? – Encipher Feb 03 '22 at 04:14
  • Every permutation is valid except for ones with two memory operands for the same instruction, or an immediate destination. e.g. `qmov REG, -8(%rsp)` / `sub $8, %rsp` would emulate `pushq REG`, assuming an ABI with a red-zone so data below the stack pointer won't get stepped on asynchronously by signal handlers or whatever. – Peter Cordes Feb 03 '22 at 04:15
  • Could you please clarify what do you denote by memory operands. I found all are either register or immediate value. – Encipher Feb 03 '22 at 04:18
  • Are you programming x86 or y86? The two architectures are not the same. – fuz Feb 03 '22 at 09:38
  • 1
    `8(%rsp)` and `-8(%rsp)` are memory operands, notice the `()` around the stack pointer! x86-64 doesn't have a way to do math on a register while reading it as an operand for another instruction, if that's what you thought the -8 and +8 were doing. Consult any basic intro to AT&T syntax (or to y86), like [What is the meaning of MOV (%r11,%r12,1), %edx?](https://stackoverflow.com/q/2883850) and https://stackoverflow.com/tags/att/info, or whatever book this exercise came from. – Peter Cordes Feb 03 '22 at 11:28

0 Answers0