microprocessors

Making large constants in C source more readable?

只谈情不闲聊 提交于 2019-11-29 10:22:15
I'm working on some code for a microprocessor. It has a few large, critical constants. #define F_CPU 16000000UL In this case, this is the CPU frequency. In Hertz. As it is, it's rather hard to tell if that's 1,600,000, 160,000,000 or 16,000,000 without manually tabbing a cursor across the digits. If I put commas in the number #define F_CPU 16,000,000UL , it truncates the constant. I've worked with a few esoteric languages that have a specific digit-separator character, intended to make large numbers more readable (ex 16_000_000 , mostly in languages intended for MCUs). Large "magic numbers"

Interrupts, Instruction Pointer, and Instruction Queue in 8086

二次信任 提交于 2019-11-28 12:44:47
Suppose an external interrupt request is made to 8086. Processor will handle the interrupt after completing the current instruction being executed (if any). Before handling of the interrupt, the state of the program will also be saved (PSW flag, registers etc.) by pushing data onto the stack segment. Now, most tutorials/documents describe that instruction pointer is also pushed onto the stack segment, which is okay because it was pointing to the next byte of instruction in the code segment (just before interrupt request was made). But what happens to the instruction queue? Is it also pushed

Playing .wav files on DOSBox's Sound Blaster device

廉价感情. 提交于 2019-11-28 11:50:20
I want to make a program in assembly/8086/masm/dosbox that turns the keyboard into various musical instruments so i need to be able to play some .wav files to produce the required sounds.I am aware of beep char and producing sound via sending frequencies to pc speaker (ports 41h,42h and 61h) but both ways are clearly not going to get me there. I searched around and found that I need to use int 21h for opening files, knowledge of .wav format and knowledge of sound programming using Sound Blaster . Unfortunately I couldn't find any helpful documentation on how to use the Sound Blaster in Dosbox

How to get time intervals on STM32?

て烟熏妆下的殇ゞ 提交于 2019-11-28 11:46:02
I want to measure how long does a single function take on STM32. The only thing I could find is SysTick_Handler . However, that is an periodic interrupt, but what I need is get time interval like: long t1 = mcu_clock(); sleep(20); long t2 = mcu_clock(); long diff = (t2 - t1); I've tried C clock() , but it didn't work and always return -1 . How can I make it? First, enable the cycle counter once at startup: CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; DWT->CYCCNT = 0; DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; then, you can access its value: unsigned long t1 = DWT->CYCCNT; /* do something */

Negative numbers are stored as 2's complement in memory, how does the CPU know if it's negative or positive?

故事扮演 提交于 2019-11-28 05:25:12
-1 can be represented in 4 bit binary as (2's complement) 1111 15 is also represented as 1111. So, how does CPU differentiate between 15 and -1 when it gets values from memory? The CPU doesn't care whether a byte holds -1 or 15 when it moves it from one place to another. There's no such thing as a "signed move" (to a location of the same size - there is a signed move for larger or smaller destinations). The CPU only cares about the representation when it does arithmetic on the byte. The CPU knows whether to do signed or unsigned arithmetic according to the op-code that you (or the compiler on

What is the minimum instruction set required for any Assembly language to be considered useful?

谁都会走 提交于 2019-11-28 05:01:01
I am studying Assembly programming in general, so I've decided to try and implement a "virtual microprocessor" in software, which has registers, flags and RAM to work with, implemented with variables and arrays. But since I want to simulate only the most basic behavior of any microprocessor , I want to create an assembly language that has only the essential instructions, only those instructions without which it couldn't be useful. I mean, there are assembly languages that can do multiplication and swapping register values, etc, but these operations are not basic because you can implement them

Making large constants in C source more readable?

别说谁变了你拦得住时间么 提交于 2019-11-28 03:38:18
问题 I'm working on some code for a microprocessor. It has a few large, critical constants. #define F_CPU 16000000UL In this case, this is the CPU frequency. In Hertz. As it is, it's rather hard to tell if that's 1,600,000, 160,000,000 or 16,000,000 without manually tabbing a cursor across the digits. If I put commas in the number #define F_CPU 16,000,000UL , it truncates the constant. I've worked with a few esoteric languages that have a specific digit-separator character, intended to make large

Instruction decoding when instructions are length-variable

安稳与你 提交于 2019-11-27 21:30:40
Here are some instructions and their corresponding encodings: 55 push %ebp 89 e5 mov %esp,%ebp 83 ec 18 sub $0x18,%esp a1 0c 9f 04 08 mov 0x8049f0c,%eax 85 c0 test %eax,%eax 74 12 je 80484b1 <frame_dummy+0x21> b8 00 00 00 00 mov $0x0,%eax 85 c0 test %eax,%eax 74 09 je 80484b1 <frame_dummy+0x21> c7 04 24 0c 9f 04 08 movl $0x8049f0c,(%esp) Today's microprocessors are often 32- or 64-bit and I guess that they usually read data from memory in 4 byte or 8 byte chunks. However, instructions can have variable length. How does a microprocessor decode these instructions and why are they not of constant

What is a stack pointer used for in microprocessors?

二次信任 提交于 2019-11-27 17:15:06
I am preparing for a microprocessor exam. If the use of a program counter is to hold the address of the next instruction, what is use of stack pointer? paxdiablo A stack is a LIFO (last in, first out - the last entry you push on to the stack is the first one you get back when you pop) data structure that is typically used to hold stack frames (bits of the stack that belong to the current function). This includes, but is not limited to: the return address. a place for a return value. passed parameters. local variables. You push items onto the stack and pop them off. In a microprocessor, the

Interrupts, Instruction Pointer, and Instruction Queue in 8086

青春壹個敷衍的年華 提交于 2019-11-27 07:12:24
问题 Suppose an external interrupt request is made to 8086. Processor will handle the interrupt after completing the current instruction being executed (if any). Before handling of the interrupt, the state of the program will also be saved (PSW flag, registers etc.) by pushing data onto the stack segment. Now, most tutorials/documents describe that instruction pointer is also pushed onto the stack segment, which is okay because it was pointing to the next byte of instruction in the code segment