A community for students.
Here's the question you clicked on:
 0 viewing
 2 years ago
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.
 2 years ago
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.

This Question is Closed

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1word 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.

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1I 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.

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1I'm using MASM as my assembler.

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1Here 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

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1If you want the libraries yourself, here they are http://asmirvine.com/asm/examples/index.htm

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1Here 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

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1My question is, is the second significantly faster than the first? And for what cases?

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1@farmdawgnation @annas

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1@imranmeah91 @nbouscal

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1And, btw, any number xor itself inputs the number itself (1023 xor 1023=1023)

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1@dpaInc , having fun reading? :3

annas
 2 years ago
Best ResponseYou've already chosen the best response.1@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

annas
 2 years ago
Best ResponseYou've already chosen the best response.1and i think 1st one is more faster then the 2nd one

annas
 2 years ago
Best ResponseYou've already chosen the best response.1the 2nd program will take more time in push and pop data in stack. so its slow ...

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1@annas , without the push and the pop, would the second be faster?

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1It says in my book I am supposed to save register values, so I included the push and pop. They aren't necessary though, right?

annas
 2 years ago
Best ResponseYou've already chosen the best response.1yes exactly inky ... the only purpose is to save register

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1Any other people's comments?

slotema
 2 years ago
Best ResponseYou've already chosen the best response.0If 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 notzero. But within the loop, you never change ecx, so it'll result in an infinite loop, I guess.

inkyvoyd
 2 years ago
Best ResponseYou've already chosen the best response.1@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.

slotema
 2 years ago
Best ResponseYou've already chosen the best response.0Ah sorry. I missed a bit where the loop instruction also decrements the ecx register. Sorry for that.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.