Skip to main content
35 votes
Accepted

What stops an assembly program from crashing the operating system?

In the end, all programs are machine code, regardless of whether the source language was assembler or a high-level language. The important thing is that there are hardware mechanisms that limit what ...
Dave Tweed's user avatar
  • 185k
34 votes
Accepted

Upload ASM code on Intel 8086 chip

The 8086 in itself doesn't have any memory, so you can't upload anything to it. You need to build a whole x86 computer with that chip in its core and then put a program in memory at the position the ...
Marcus Müller's user avatar
31 votes
Accepted

Fiducial marks: Do they need to be a pad or is it okay if I use the top silk layer?

You need to use a copper pad, with a corresponding clearance in the soldermask and ground planes. The reason for not using the silk layer, is the tolerances of aligning the silk are typically ...
Tom Carpenter's user avatar
22 votes
Accepted

How to program the CPU when making a small microcomputer?

You use an in-circuit serial programmer (ICSP), debugger, or JTAG that sits between your computer's USB port and your board. You lay out the board so the programmer connects to the board and ...
DKNguyen's user avatar
  • 58.1k
20 votes
Accepted

What does [WEAK] mean in STM32 startup assembly code?

It says the implementation of the function should be weakly linked (as opposed to strongly linked, which is the usual). This allows providing a "fallback" implementation of a function, in case no ...
dim's user avatar
  • 16.4k
19 votes

How to program the CPU when making a small microcomputer?

Designing a board from scratch like this, with a CPU you haven't used before, can be difficult, and probably won't work. When working with a new CPU, the safest approach is to get hold of an off-the-...
jayben's user avatar
  • 1,590
17 votes

How does an operating system or program detect the CPU model name?

For x86, you can use the CPUID instruction. It allows you to query various pieces of information about the CPU. It's built right into the CPU (and is not an operating system service).
Jonathan S.'s user avatar
  • 20.8k
14 votes

Upload ASM code on Intel 8086 chip

You need to attach something to the CPU memory bus at specific starting location from where the CPU can fetch program code to execute. For the 8086, it starts executing code from memory address ...
Justme's user avatar
  • 196k
12 votes
Accepted

Assembly code, what does it do?

These look like instructions for a RISC-V microprocessor. https://riscv.org/wp-content/uploads/2017/05/riscv-spec-v2.2.pdf ori is the "OR Immediate" instruction. slli is a "Left Shift ...
user4574's user avatar
  • 13.5k
12 votes

Compile time error with inline PIC assembly in MPLAB XC16 C

This: asm volatile ("BSET PORTB, #8"); should work if you are using the assembler from the xc16 compiler. It's a syntax problem. The bit number is an ...
Mike's user avatar
  • 2,619
11 votes
Accepted

Why this code wasn't written in a much simpler way?

You are right in that it appears the code you show is silly. Perhaps whatever machine this runs on can't do immediate operations to set bits on I/O ports, and that that's why something like SETB P2.2 ...
Olin Lathrop's user avatar
11 votes

What stops an assembly program from crashing the operating system?

Many multitasking operating systems use a data structure called a Process Control Block (PCB) to take care of the register overwrite problem. When you run your code, the OS creates a new process to ...
jtst's user avatar
  • 141
11 votes
Accepted

How does an operating system or program detect the CPU model name?

The architecture defines what results software can expect when running on an implementation conforming to the architecture. It is essentially a contract that ensures binary compatibility between ...
awjlogan's user avatar
  • 8,069
11 votes
Accepted

Logic value of a single input pin into a microcontroller

Generally, if the MCU has no mechanism of reading just one bit, you read the whole port and mask off the irrelevant bits you want to ignore to zero and then compare if the remaining bit makes the ...
Justme's user avatar
  • 196k
10 votes
Accepted

Why does __libc_init_array cause an exception?

Solution is to add -mcpu=cortex-m4 and -mthumb to your LFLAGS variable. I'm not super-well-versed on GCC internals; please, someone correct me if I'm mistaken. The reason the flags need to be added ...
pgvoorhees's user avatar
  • 2,556
10 votes
Accepted

How to produce a middle C on intel 8080?

DCR C decrements the C register and sets flags; it does not affect the accumulator (aka A register). The only instruction in this sequence which affects the ...
Russell Borogove's user avatar
10 votes
Accepted

How can I do immediate addition in the Atmel AVR instruction set?

There is a subi instruction - "subtract immediate". You can easily do addition using this instruction, so one can speculate there isnt a need for a ...
Tom Carpenter's user avatar
9 votes

Why this code wasn't written in a much simpler way?

The code is almost certainly for a processor using the 8051 instruction set. On that processor, the code variation you give would have the same effect as the original except that it would run faster. ...
supercat's user avatar
  • 47.6k
9 votes
Accepted

How to build the simplest assembly file in MPLabX IDE 5.4

Microchip has made it very to hard to develop 8-bit assembly language applications using the latest release of MPLABX v5.40. To help I have crafted a PIC16F84A example project you can find here. This ...
Dan1138's user avatar
  • 1,449
9 votes

Fiducial marks: Do they need to be a pad or is it okay if I use the top silk layer?

A fiducial must be in the top and bottom copper layers so it has perfect registration with respect to the rest of the component pads. In our system a fiducial was a component (complete with a ...
AnalogKid's user avatar
  • 26.2k
9 votes
Accepted

ARM How to invoke branching?

From ARM conditionals you can readily find that the instruction examines the Z, N, and V status flags and branches when Z=0 & N=V. Since it examines the V status flag and not the C status flag, ...
jonk's user avatar
  • 79.7k
8 votes

As a computer science engineering graduate, do I need to learn Assembly language in today's day and age?

Not knowing assembly is just fine UNTIL you have to debug something non trivial. Interrupt trampolines, interrupt entry and exit stubs, missing memory barriers before cooking off a DMA transfer, ...
Dan Mills's user avatar
  • 18k
8 votes
Accepted

What does _SFR_IO8(0x04) do? AVR

It is a macro to access AVR IO address space registers, and in that address space, register 4 seems to be DDRB. You might want to actually use the datasheet as the register reference, instead of ...
Justme's user avatar
  • 196k
8 votes

Logic value of a single input pin into a microcontroller

How can I get the value of the input pin P0.1? You may "jump" on a bit value (e.g. JB, JNB): ISA But this limits my action since I'm obligated to have all other pins of port P0 to L. Not ...
devnull's user avatar
  • 11k
7 votes

Why this code wasn't written in a much simpler way?

The assembly code given is likely compiler-generated. It is the unoptimized version of the following C statements, where P2_2 and ...
D Krueger's user avatar
  • 260
7 votes
Accepted

Expression calculated at assembly time

The assembler (compiler) has to calculate the constant at assembly time, so the compilation to binary is marginally slower. A human cannot tell the difference so the compilation time it takes is ...
Justme's user avatar
  • 196k
7 votes

Upload ASM code on Intel 8086 chip

The 8086 loads an instruction from the Data memory space after it completes its power on and reset is deasserted. This instruction is the first instruction of whatever program or bootloader you want ...
Voltage Spike's user avatar
  • 93.2k
7 votes
Accepted

Are `call` and `return` usually instructions in a modern ISA?

The short answer for any reasonable definition of modern is "yes". Even little things like PIC16 have call and return. ARM, for historical reasons, spells CALL as "bl" and RETURN ...
pjc50's user avatar
  • 47.4k
6 votes
Accepted

PIC programming in Assembly

de is an assembler directive to declare an EEPROM data byte. org is also a directive. You can find a full list of assembler directives in the MPASM manual (see 4.17 for de). In general all ...
Spehro 'speff' Pefhany's user avatar
6 votes

Help in understanding Store Word (SW) instruction in Risc-V

With RISC-V assembler, the operand order is destination/source except for stores. Thus, your example instruction reads: ...
maxschlepzig's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible