Microchip
直播中

李晓欢

7年用户 351经验值
私信 关注
[问答]

如何阅读汇编代码?

嗨,那里。我想问一下,阅读汇编代码有什么技巧吗?例如:这个C代码:翻译成:我试着读这个小片段,但是它很难理解。1。Goto 0xC12。XORLW 0x0(任何值XOLD与0是相同的值,如果W是0和gt;z=1;否则Z=0)3。BTFSC状态,0x2(我不知道Z中现在是什么值,因为我不知道W),如果Z=0∶1。XOLLW 0x6(我不知道这是怎么做的,为什么XOR可以在操作数0x6上做?)如果Z!= 0∶1。在这种情况下,这个变量Ledii i与函数KEY,ununkiti化完全无关,我不知道如何挖掘。请给我一些阅读汇编的提示,谢谢。

以上来自于百度翻译


      以下为原文

    Hi, there. I want to ask that is there any skill to read assembly code?
For example:
This C code:
void KEY_UnlockInitialization(void){
    while(KEYbits.INITIALIZATION != ON);
    KEYbits.INITIALIZATION = OFF;
}
is translated to:
10: void KEY_UnlockInitialization(void){
11: while(KEYbits.INITIALIZATION != ON);
08C0 28C1 GOTO 0xC1
08C1 0020 MOVLB 0x0
08C2 1C4C BTFSS KEYbits, 0x0
08C3 28C5 GOTO 0xC5
08C4 28C6 GOTO 0xC6
08C5 28C1 GOTO 0xC1
12: KEYbits.INITIALIZATION = OFF;
08C6 104C BCF KEYbits, 0x0
13: }
08C7 0008 RETURN
86: case TEMP_TOO_HIGH_DURING_CHARGE:
87: switch(led_i){
009E 28BF GOTO 0xBF
00BF 0020 MOVLB 0x0
00C0 0845 MOVF 0x45, W
00C1 3A00 XORLW 0x0
00C2 1903 BTFSC STATUS, 0x2
00C3 28C8 GOTO 0xC8
00C4 3A06 XORLW 0x6
00C5 1903 BTFSC STATUS, 0x2
00C6 28D0 GOTO 0xD0
00C7 28B7 GOTO 0xB7
00C8 0844 MOVF led_i, W
00C9 3A00 XORLW 0x0
00CA 1903 BTFSC STATUS, 0x2
00CB 289F GOTO 0x9F

/*code Omitted*/
I tried to read this small snippet but it's so hard to understand.

1. GOTO 0xC1
2. XORLW 0x0 (any value XORed with 0 is the same value, if w is 0 -> z = 1; otherwise z = 0)
3. BTFSC STATUS, 0x2 (I don't know what value is in z now, because I don't know w)

if z = 0:
1. XORLW 0x6 (I don't know what this doing, why XOR can do on operand 0x6?)
if z != 0:
1. MOVF led_i, W(this variable led_i is totally not related to function KEY_UnlockInitialization)

In this situation, I don't know how to dig in. Please give me some hint to read assembly, thank you.

回帖(19)

李维兴

2018-9-26 09:55:37
看起来像嵌套的开关()语句。外部开关()语句中使用的表达式的数据类型是什么?TimeTotooHyHug收费是什么价值?内部开关()语句中使用的LeDyi的数据类型是什么?那么?我看不到在KEY-UNCONKITIALIZIZION()函数中使用的变量LeDyi。请阅读PIC数据表的“指令集摘要”章节。

以上来自于百度翻译


      以下为原文

   
Look like you have nested switch() statements. What is the data type for the expression used in the outer switch() statement? What value is TEMP_TOO_HIGH_DURING_CHARGE? What is the data type of led_i used in the inner switch() statement?
 

So? I don't see the variable led_i used in your KEY_UnlockInitialization() function.
 

Read the "Instruction Set Summary" chapter of your PIC datasheet.
举报

张蕾

2018-9-26 10:14:56
HiTeTeTrad是在ASM学习编程的时候,用一些简单的东西练习LED闪光灯和用ADC通过电位器控制LED频率。但是让我们看看我是否能帮助你进入正确的状态。XORE和“0”不影响价值,而是更新。从W内容的Z标志通知XOR操作是在零测试之前进行的。这配置了一些类似IF(W=0)或IF(W)的东西。= 0),这取决于后续的代码。关于“Redii i”变量的问题,与这个“C”代码集无关,它可能是编译器的一个工件,它可能会提前更新它,以便在后面的“C”源中进行某些操作。它也可以暂时重用某些不在使用中的自动变量。有一点可能是误导性的,即汇编代码在执行方面可能出现无序。注意地址栏。发生在一些从对象文件读取的浏览器中。

以上来自于百度翻译


      以下为原文

    Hi
 
Betetr way is to invest sometime in learning to program in ASM, practising with some simple things lie the led flashing and controling LED frequency with an potentiometer via an ADC.
 
But let's see if I can help put you in the right state of mind.

XORing with '0' doesn't affect the value but updates the Z flag from the contents of W. Notice the XOR operation is imediatly before a test for Zero.
This configures something like if( W == 0) or if(W != 0), depending on the subsequent code.
 
The question about the 'led_i' variable, beeing unrelated to this 'C' code snipset is probably an artifact of the compiler, it might be updating it in advance for some operation that apears latter in the 'C' source. It also can be temporary reusing some automatic variable not in use at the moment.
 
One thing that can be misleading is that, the assembly code might appear out of order in terms of execution. Pay attention to the address column. Happens with some viewers that read it from object files.
 
 
 
HIH
 
Best regards
Jorge
 
 
 
 
 
举报

冯栋

2018-9-26 10:31:38
到1: 0:是的,我把枚举和交换应用在一起,就像下面一样,这也让我感到困惑!莱德基是个局外人,我不知道他为什么在这里。事实上,我在阅读这一章的时候阅读了汇编。但还是做不到。

以上来自于百度翻译


      以下为原文

    To 1and0:

Yes, and I applied enumeration and switch together, something like below.
typedef enum{
// CHARGER_WAIT_COMM_CABLE_IN,
    CHARGER_WAIT_BATTERY_IN,
    BATTERY_IN,
    BATTERY_VOLTAGE_TOO_LOW, //under 14
    BATTERY_VOLTAGE_TOO_HIGH,
    CHARGER_VOLTAGE_TOO_HIGH,
    BATTERY_OVER_CURRENT,
    TEMP_TOO_LOW_INITIAL,
    TEMP_TOO_HIGH_INITIAL,
    TEMP_TOO_HIGH_DURING_CHARGE,
    BATTERY_BEING_CHARGED,
    BATTERY_FULL,
    UV_OVERTIME,
    CV_OVERTIME,
    WHOLE_CHG_OVERTIME,
    COMMUNICATION_FAILED,
    CHARGER_CHARGING_BUT_NO_CURRENT,
}LED_CASES;
    
extern volatile LED_CASES led_case;
switch(led_case){
            case CHARGER_WAIT_BATTERY_IN:
                switch(led_i){
                    case 0:
                        led_i = led_i + 10;
                        LED_RED = ON;
                        break;
                    case 100:
                        led_i = led_i + 10;
                        LED_RED = OFF;
                        break;
                    case 250:
                        led_i = led_i + 10;
                        LED_RED = ON;
                        break;
                    case 350:
                        led_i = led_i + 10;
                        LED_RED = OFF;
                        break;
                    case 1850:
                        led_i = 0;
                        break;
                    default:
                        led_i = led_i + 10;
                        break;
                }
                break;

This makes me confused too! The led_i is an outsider, I don't know why he is here.

Actually, I read assembly while reading this chapter. But still can't make it.
举报

冯栋

2018-9-26 10:37:23
JorgeF:我想问一个问题,如果W的内容是0B1111 0000,X0x0与XORD。我猜的操作如下:W:1111 0000:0000 0000 ---------R:1111,结果,Z标志是0。如果W的内容为0Bxxxxxxxx,并与0x6. w:xxxxxxxx:0000 0110 -------------RX:XXXXXAS结果,Z标志为0?如果以上是真的,在我的POST .XORLW 0x0(假设z=0(w)!= 0),因为我们不知道W中的值是什么,然后编译器做:XORLW 0x6为什么需要再次做这行?你已经知道Z是零,你再次做这个指令来更新Z到0?这是没有意义的。如果这行只是为了执行下一行:BTFSC状态,0x2,那么转到:Goto 0xB7,这是编译器风格的汇编代码的正常情况吗?

以上来自于百度翻译


      以下为原文

    To JorgeF:

I want to ask a question.
If the content of W is 0b1111 0000, and XORed with 0x0.
The operation I guessed is below:
W: 1111 0000
 : 0000 0000
-----------------
R: 1111 0000
 
as a result, the Z flag is 0?
 
If the content of W is 0bxxxx xxxx, and XORed with 0x6.
 
W: xxxx  xxxx
 : 0000 0110
-----------------
R: xxxx  x11x
 
as a result, the Z flag is 0?
 
If above is true, in my post.
 
XORLW 0x0 (assume that z = 0(w != 0), because we don't know what value in W)
then the compiler do:
XORLW 0x6
Why need to do this line again? You already know the z is zero and you do this instruction again to update z to 0?
It doesn't make any sense.
 
If this line is just for executing next line:
BTFSC STATUS, 0x2
Then just go to:
GOTO 0xB7
 
 
Is this a normal situation to compiler-style assembly code?
 
 
举报

更多回帖

发帖
×
20
完善资料,
赚取积分