Write an assembly procedure called increment that is callable from C. The procedure should take a pointer to 32-bit integer as a parameter, and should increment the integer to which the parameter points. The C prototype for the function is as follows:
void increment (int *p);
Provide only the assembly code from the procedure label to the ret instruction.
So, the question has to be done in Assembly NASM x86-64 (in this case, E registers since it's asking for 32-bit). Assuming everything else is already declared and defined such as extern, global, section .data, it's generally a short segment of logical instructions of 3-12 lines of code in _start: that I have to code; this is the code:
increment:
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-8], rdi
mov rax, QWORD PTR [rbp-8]
mov eax, DWORD PTR [rax]
lea edx, [rax+1]
mov rax, QWORD PTR [rbp-8]
mov DWORD PTR [rax], edx
nop
pop rbp
ret
I know that PTR is't apart of NASM keyword, but my confusion comes from whether to remove PTR or keep it, and whether I should be using both E registers and R registers. I believe mine is somewhat correct, but if someone could double check my code to see if it's logic makes sense from the question standpoint, that'd be wonderful.
The code below is a C file I have to call from using such things like scanf or printf, but since I'm not using those for this code I wonder if I'm doing it wrong since those are important to C. From what I understand there are other ways of going about with this question; I'm not sure how I would go about in translating this C code into NASM through alternative means:
void increment (int *p) {
*p = *p + 1;
}