writing a program from placing arbitrary value to 32 bit register.

Thread Starter

yef smith

Joined Aug 2, 2020
240
Hello, I want to write a program that takes a binary number and a location and puts it inside a 32 bit register.
Is there a manual i could use to accomplish that?
Some google keyword so could use that will pont me to the right direction?
Thanks
 

djsfantasi

Joined Apr 11, 2010
7,693
Wow. There’s a lot of missing information there. What’s the value of location represent? Where’s the binary number? In the location? What processor are you using (registers depend on the processor)? What language is this program written in?
 

Papabravo

Joined Feb 24, 2006
16,132
Hello, I want to write a program that takes a binary number and a location and puts it inside a 32 bit register.
Is there a manual i could use to accomplish that?
Some google keyword so could use that will pont me to the right direction?
Thanks
You would use a load register from memory instruction. All processors have such an instruction. The manual is called "Instruction Set Manual" for the processor of interest. Here is the one for an STM32 Cortex - M4

https://www.st.com/resource/en/prog...pus-programming-manual-stmicroelectronics.pdf

LDR R8, {R10]

would load register 8 with the contents of the memory location pointed at by R10
 

Thread Starter

yef smith

Joined Aug 2, 2020
240
Hello Papabravo, i tried to search in the document you gave the words " Instruction Set Manual " it didnt find anything.
 

Papabravo

Joined Feb 24, 2006
16,132
Hello Papabravo, i tried to search in the document you gave the words " Instruction Set Manual " it didnt find anything.
The link in my message was obtained as the #1 google hit to the following search term. The LDR innstruction is on page 71

"STM32 Instruction Set Manual"

I can't imagine why my Google is better than your Google unless it knows that I have been around longer.
 
Last edited:

Thread Starter

yef smith

Joined Aug 2, 2020
240
Hello djsfantasi,i am using STM32 in 32bit register i and for example to place on 7th place and after it the binary
0b010
is there some function you knowor a manual that i could use to implement such a thing?
Thanks.
Wow. There’s a lot of missing information there. What’s the value of location represent? Where’s the binary number? In the location? What processor are you using (registers depend on the processor)? What language is this program written in?
 

djsfantasi

Joined Apr 11, 2010
7,693
You have the manual, provided by Papabravo. In the document at his link, section 3.4.2 contains the description of the load register from memory command - LDR.
 

jpanhalt

Joined Jan 18, 2008
11,088
I don't know the equivalent in C, but putting an 8-bit number anywhere in a 32-bit register would be easy. Say, you want the bits to go from 8 to 15. Just pad the 8-bit number, e.g., abcdefgh00000000, then OR it to the 32-bit register (assuming bts 8..15 are already clear). That preserves bits 0..7. There are different variations on that theme. One variation would be to mask bits 8..15 (make zero by AND'ing) , then XOR b'0000 0000_0000 0000_abcdefgh_0000 0000' and so forth.
 

Papabravo

Joined Feb 24, 2006
16,132
In a LOAD-STORE architecture the way you manipulate a bit field is with a LOAD instruction and a SHIFT instructions:
ASR, LSL, LSR, ROR, & RRX detailed on page 86

In a two step process you get the value you want into a register, then you move it to the position of interest.
 

BobaMosfet

Joined Jul 1, 2009
1,776
Hello, I want to write a program that takes a binary number and a location and puts it inside a 32 bit register.
Is there a manual i could use to accomplish that?
Some google keyword so could use that will pont me to the right direction?
Thanks
You're statement makes no sense. You can only put one 32-bit value in a 32-bit register- which one, the binary number or the location (address)? Learn how to program- masking, bit shifting, ANDing, ORing, etc.

Title: Standard C [Quick Ref]
Author(s): P.J.Plauger, Jim Brodie
ISBN: 1-55615-158-6

Title: Algorithms in C, 3rd Ed. [Parts 1-4, Fundamentals, Data Structures, Sorting, Searching]
Author: Robert Sedgewick
ISBN: 0-201-31452-5
 
Top