When a line of code shown below is compiled(X86), corresponding assembly instruction is generated. 895 is an -ve number and is stored in 2's complement form at the memory location pointed by %esp.
int a = -895 --> compiler ---> movl $-895, 24(%esp)
My doubt is, does assembler directly converts -895 to 2's complement form and generates machine instruction or does CPU's ALU while executing corresponding machine instruction with -895 as argument does it and store in memory location?
The assembler does it. It most likely first converts 895 into binary and then negates it and the result goes into the compiled code. Negation obviously occurs in the CPU (as does execution of the entire assembler), most likely as a single instruction (e.g. NEG register
).