使用AVR时如何查找变量的地址? [英] How to find the address of a variable when using AVR?

查看:103
本文介绍了使用AVR时如何查找变量的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个程序,以在使用AVR-GCC编译的Teensy微控制器上检测位图的像素级冲突.我试图弄清楚如何计算屏幕上位图的单个字节的位置,并被告知我应该使用指针.我看不到位图字节的物理地址与其在屏幕上的位置之间的关系,但我想调查一下.问题是,我无法打印此地址. AVR没有printf,而且我不知道如何将其显示在屏幕上.有人可以在终端中以某种方式产生此地址吗?

I am trying to write a program that detects pixel level collision of bitmaps on a Teensy micro controller compiling with AVR-GCC. I am trying to work out how to calculate the position of a single byte of the bitmap on the screen and have been told I should be using pointers. I don't see the relationship between the physical address of a bitmap byte and it's position on the screen, but I would like to investigate. The problem is, I have no way of printing this address. AVR doesn't have printf and I don't know how to get it to display on the screen. Does anyone have a way of producing this address somehow in the terminal?

即如果我有位图并想要打印出第一个字节的地址,那么我需要写些什么来完成此操作:

i.e. if I have a bitmap and want to print out the address of the first byte, what would I need to write to complete this:

??? *bit = &car_bitmap[1]; 
???("%??? ", bit);

推荐答案

假设您有一个正常工作的printf(),它应该可以工作:

Assuming you have a working printf(), this should work:

void * const bit = &car_bitmap[1]; 
printf("%p\n", bit);

%p的打印位置.其他指针类型应强制转换为void *以便匹配,但无论如何我还是将void *用作地址进入帧缓冲区.

Where %p is how to print a void *. Other pointer types should be cast to void * in order to match, but I used a void * for the address into the framebuffer anyway.

这篇关于使用AVR时如何查找变量的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆