[SOLVED] ADC - Carry is being weird. Am I doing something wrong?
I am learning assembly and tried below code and I'm confused because ADC keeps adding 1. Am I completely misunderstanding on this? :(
Code: Select all
.section .text
.thumb_func
_start:
movs r0, #0
movs r1, #0
adcs r0, r1 @ 1 instead of 0
movs r0, #0xFFFFFFFF
movs r1, #1
adcs r0, r1 @ 0 instead of 1
nop
Last edited by haruharu on Sat Jun 14, 2025 5:29 pm, edited 1 time in total.
- dp11
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 1694
- Joined: Thu Dec 29, 2011 5:46 pm
Re: ADC - Carry is being weird. Am I doing something wrong?
What was the state of the carry flag before your code runs?
Re: ADC - Carry is being weird. Am I doing something wrong?
Always interested in innovative audio startups needing help and investment. Look for InPoSe Ltd or Future Horizons on LinkedIn to find me (same avatar photograph)
Re: ADC - Carry is being weird. Am I doing something wrong?
Ah thanks! I now understand the behavior of carry bit in xpsr. I somehow imagined carry bit would be updated after every instruction which now I see how silly that thought was :D Now things are appearing as expected.
Code: Select all
.section .text
.thumb_func
_start:
movs r0, #0
movs r0, #1
cmp r0, r1 @ This clears carry bit in xpsr.
mov r0, #0 @ r0 = 0
mov r1, #0 @ r1 = 0
adc r0, r1 @ r0 = r0 + r1 + carry(0) = 0
movs r0, #0xFFFFFFFF @ r0 = max
movs r1, #1 @ r1 = 1
adds r0, r1 @ Overflowed, r0 becomes 0 and carry bit is set.
adc r0, r0 @ r0 = r0 + r0 + carry(1) = 1
nop
Return to "Bare metal, Assembly language"
Jump to
- Community
- General discussion
- Announcements
- Other languages
- Deutsch
- Español
- Français
- Italiano
- Nederlands
- 日本語
- Polski
- Português
- Русский
- Türkçe
- User groups and events
- Raspberry Pi Official Magazine
- Using the Raspberry Pi
- Beginners
- Troubleshooting
- Advanced users
- Assistive technology and accessibility
- Education
- Picademy
- Teaching and learning resources
- Staffroom, classroom and projects
- Astro Pi
- Mathematica
- High Altitude Balloon
- Weather station
- Programming
- C/C++
- Java
- Python
- Scratch
- Other programming languages
- Windows 10 for IoT
- Wolfram Language
- Bare metal, Assembly language
- Graphics programming
- OpenGLES
- OpenVG
- OpenMAX
- General programming discussion
- Projects
- Networking and servers
- Automation, sensing and robotics
- Graphics, sound and multimedia
- Other projects
- Media centres
- Gaming
- AIY Projects
- Hardware and peripherals
- Camera board
- Compute Module
- Official Display
- HATs and other add-ons
- Device Tree
- Interfacing (DSI, CSI, I2C, etc.)
- Keyboard computers (400, 500, 500+)
- Raspberry Pi Pico
- General
- SDK
- MicroPython
- Other RP2040 boards
- Zephyr
- Rust
- AI Accelerator
- AI Camera - IMX500
- Hailo
- Software
- Raspberry Pi OS
- Raspberry Pi Connect
- Raspberry Pi Desktop for PC and Mac
- Beta testing
- Other
- Android
- Debian
- FreeBSD
- Gentoo
- Linux Kernel
- NetBSD
- openSUSE
- Plan 9
- Puppy
- Arch
- Pidora / Fedora
- RISCOS
- Ubuntu
- Ye Olde Pi Shoppe
- For sale
- Wanted
- Off topic
- Off topic discussion