Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

Wrote two solutions to a programming problem. The problem was to find the XOR between all of the whole numbers between two whole numbers. The first whole number must be smaller than the second.

Computer Science
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SEE EXPERT ANSWER

To see the expert answer you'll need to create a free account at Brainly

word size is 32 bit unsigned. For example, inputting 3 and 10 would get 3->0000 0000 0000 0000 0000 0000 0000 0011 10->0000 0000 0000 0000 0000 0000 0000 1010 I'm going to omit those extra zero's for brevity's sake, and this is in binary (((((((11 xor 100) xor 101) xor 110) xor 111) xor 1000) xor 1001) xor 1010) which equals 1000, which is 8 in decimal.
*I mean, dword
I am currently trying to learn some assembly, so I wrote a little program in ASM, using libraries that are provided for me in the book. These libaries do I/O for me - nothing more really.

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

I'm using MASM as my assembler.
Here is the source code: INCLUDE Irvine32.inc .data prompt BYTE "Enter a long unsigned integer.",0 ;our prompt .code main PROC call Crlf mov edx,OFFSET prompt call WriteString ;writes the null -terminated string with the offset in edx call ReadDec ;reads an unsigned 32 bit integer from the keyboard, and returns it in eax call Crlf ;writes end of line sequence to the console window. call Crlf mov ebx,eax mov edx,OFFSET prompt call WriteString call ReadDec call Crlf call Crlf ;first value is ebx, and second is eax. eax>ebx cmp eax,ebx jz skip sub eax,ebx mov ecx,eax mov eax,ebx L1: inc eax xor ebx,eax dec ecx cmp ecx,0 jnz L1 mov eax,ebx skip: call WriteDec call DumpRegs ;displays register values in the console window exit main ENDP END main
If you want the libraries yourself, here they are http://asmirvine.com/asm/examples/index.htm
Here is the source of a revised version. INCLUDE Irvine32.inc .data prompt BYTE "Enter a long unsigned integer.",0 .code main PROC call Crlf mov edx,OFFSET prompt call WriteString call ReadDec call Crlf call Crlf mov ebx,eax mov edx,OFFSET prompt call WriteString call ReadDec call Crlf call Crlf mov ecx,eax ;first value is ebx, and second is ecx. ecx>ebx sub ecx,ebx push ebx push ecx mov eax,0 inc ecx L1: xor eax,ebx inc ebx loop L1 pop ecx pop ebx call WriteDec call DumpRegs exit main ENDP END main
My question is, is the second significantly faster than the first? And for what cases?
And, btw, any number xor itself inputs the number itself (1023 xor 1023=1023)
@dpaInc , having fun reading? :3
@inkyvoyd xor AX, AX is used to set the register's value to zero because 1 xor 1= 0 0 xor 0 =0 1 xor 0 = 1 0 xor 1 = 1
and i think 1st one is more faster then the 2nd one
the 2nd program will take more time in push and pop data in stack. so its slow ...
@annas , without the push and the pop, would the second be faster?
yes
It says in my book I am supposed to save register values, so I included the push and pop. They aren't necessary though, right?
yes exactly inky ... the only purpose is to save register
Any other people's comments?
If you assume that all instructions take a single processor cycle (thus assuming no hazards and/or memory stalls), determining which one is better is a case of just counting the instructions. Your first program uses 6 instruction out of the loop (ignoring IO, since both programs have to do that) and 5 instructions inside the loop. That makes a total of 6+5n instructions (where n is the number of xors you need to do). That is from "cmp eax, ebx" up to the skip label. The second program uses 7 + 3n instructions. From "sub ecx, ebx" to "pop ebx". Thus, the second program appears to be faster indeed. The impact of memory misses can be quite huge, but I don't know whether or not the pushes or pops are likely to cause one. One more remark is that I'm not sure the second program will actually work. The "loop" instruction will keep on jumping as long as the ecx register is not-zero. But within the loop, you never change ecx, so it'll result in an infinite loop, I guess.
@slotema , it works perfectly fine for me. I'm using a book that is based on MASM - might be syntax that is different from the assembler you are using.
Ah sorry. I missed a bit where the loop instruction also decrements the ecx register. Sorry for that.

Not the answer you are looking for?

Search for more explanations.

Ask your own question