Click here to Skip to main content
15,920,956 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionfunction translated to ASM Pin
Calin Negru24-Jan-22 23:42
Calin Negru24-Jan-22 23:42 
AnswerRe: function translated to ASM Pin
CPallini25-Jan-22 0:10
mveCPallini25-Jan-22 0:10 
GeneralRe: function translated to ASM Pin
Calin Negru25-Jan-22 11:24
Calin Negru25-Jan-22 11:24 
GeneralRe: function translated to ASM Pin
CPallini25-Jan-22 20:00
mveCPallini25-Jan-22 20:00 
AnswerRe: function translated to ASM Pin
trønderen25-Jan-22 0:51
trønderen25-Jan-22 0:51 
GeneralRe: function translated to ASM Pin
Fly Gheorghe25-Jan-22 8:59
Fly Gheorghe25-Jan-22 8:59 
GeneralRe: function translated to ASM Pin
trønderen25-Jan-22 23:23
trønderen25-Jan-22 23:23 
GeneralRe: function translated to ASM Pin
Fly Gheorghe28-Jan-22 3:39
Fly Gheorghe28-Jan-22 3:39 
I am trying to keep discussions to a general level, so that statements were valid 20 years ago, are valid today and will be valid 20 years from now, at least with the classic CPU architecture.

1) Regarding stack management:
From CPU perspective, when entering a procedure, the stack is just a memory contiguous area defined by a segment descriptor and by a stack pointer. It is irrelevant how this memory area was allocated: statically, when the process was started or dynamically before the call. Dynamically means that somebody must deallocate that area as well.

2) Run-time/development environment matters when choosing how to pass/return parameters
Allocating memory on the heap is fine, assuming you have a heap in the first place. This assumes calls to the OS to get/release memory, but what if don't have on OS at all? What if you write code for a dedicated hardware controller and the only memory is statically defined?

There are special environments like space/military/medical in which you are not even allowed to use dynamic memory allocation, for obvious reasons.

3) I still say that a good insight in hardware and in assembly language is essential for becoming a good software engineer. If not, who should have these insights?
I don't write assembler as well nowadays, but the fact that once I did helps me write better C/C++/C# code.

4) XOR AX, AX vs. MOV AX, 0
It is not only about speed, but also about instruction encoding.
"XOR AX, AX" occupies just one byte of memory, while "MOV AX, 0" occupies one byte for the op code and 2 bytes for the "immediate" 16-bit operand. If you consider 32 bits, then "MOV EAX, 0" occupies 5 bytes: one for the instruction code and 4 bytes for the 32-bit operand. The compiler treats all immediate operands in the same way.
Following the same logic, on a 64-bit CPU, "MOV RAX, 0" will occupy 10 bytes, since the operand is on 8 bytes, while "XOR RAX, RAX" will be on 2 bytes only (64-bit prefix and op code).

There is also another aspect.
If you want to do compare operations then you must be sure that the arithmetic flags are correctly set with respect to the entity you want to compare. A conditional jump "JNZ address" will not work as expected after "MOV AX, 0" (if the AX is what you want to jump on) because "MOV" does not set any of the arithmetic flags, but will work fine after "XOR AX, AX", because "XOR" does.

So those students who insisted on using XOR instead of MOV were fully right.
GeneralRe: function translated to ASM Pin
Richard Andrew x6430-Jan-22 4:48
professionalRichard Andrew x6430-Jan-22 4:48 
AnswerRe: function translated to ASM Pin
k505430-Jan-22 5:11
mvek505430-Jan-22 5:11 
GeneralRe: function translated to ASM Pin
Richard Andrew x6430-Jan-22 11:29
professionalRichard Andrew x6430-Jan-22 11:29 
GeneralRe: function translated to ASM Pin
Calin Negru31-Jan-22 6:49
Calin Negru31-Jan-22 6:49 
QuestionVS2019 - missing dialog editor? Pin
charlieg23-Jan-22 11:15
charlieg23-Jan-22 11:15 
SuggestionRe: VS2019 - missing dialog editor? Pin
Graham Breach23-Jan-22 21:30
Graham Breach23-Jan-22 21:30 
GeneralRe: VS2019 - missing dialog editor? Pin
charlieg24-Jan-22 2:31
charlieg24-Jan-22 2:31 
AnswerRe: VS2019 - missing dialog editor? Pin
Victor Nijegorodov23-Jan-22 21:33
Victor Nijegorodov23-Jan-22 21:33 
GeneralRe: VS2019 - missing dialog editor? Pin
charlieg24-Jan-22 2:32
charlieg24-Jan-22 2:32 
AnswerRe: VS2019 - missing dialog editor? Pin
charlieg25-Jan-22 7:34
charlieg25-Jan-22 7:34 
QuestionMessage Closed Pin
21-Jan-22 18:09
Member 1496877121-Jan-22 18:09 
AnswerRe: More about "system" call - sort of repost Pin
k505421-Jan-22 18:38
mvek505421-Jan-22 18:38 
GeneralMessage Closed Pin
22-Jan-22 4:40
Member 1496877122-Jan-22 4:40 
GeneralRe: More about "system" call - sort of repost Pin
k505422-Jan-22 5:19
mvek505422-Jan-22 5:19 
GeneralRe: More about "system" call - sort of repost Pin
Richard MacCutchan22-Jan-22 6:28
mveRichard MacCutchan22-Jan-22 6:28 
QuestionMessage Closed Pin
21-Jan-22 6:37
Member 1496877121-Jan-22 6:37 
AnswerRe: How to read "compiier output " Pin
k505421-Jan-22 7:15
mvek505421-Jan-22 7:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.