ARM数转换程序 [英] ARM number conversion program

查看:159
本文介绍了ARM数转换程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个程序,将一些转换基于IEEE TNS(大端),反之亦然。
我很新的ARM和装配一般。我没有得到一个错误,它只是没有按预期工作,我最好的AP preciate它,如果任何人都可以看到它。每一道线条都是有问题,发表了意见子程序实际上这里是解压IEEE的程序,按预期它不工作,我不明白为什么。编辑:IEEE和TNS数字有3个部分,我试图抢或独立的3个部分使用口罩。解包的过程是使用口罩,每个部分放入一个单独的寄存器,这样我可以为了它转换操作每一个部分。目前,我想确认解压程序的工作原理是调用它,然后打印寄存器。这些数字是不是没有打印或打印不正确的结果。结束编辑的我没有写的转换程序,但我有一个psudo code算法我可以发布,如果你愿意的话。只是让我知道是否有其他任何你想知道的。在code:

 区转,code
SWI_WriteC EQU&放大器; 0;在r0输出特性
SWI_WriteL EQU和2;在r0输出字符串
SWI_Exit EQU及11条;完成计划
    条目    ADR R0,STRING;负载串
    SWI SWI_WriteL;打印字符串
    LDR R1,IEEE,IEEE加载NUM到R0
    BL打印;打印的编号
    BL UnpackIEEE;调用子程序UnpackIEEE
    ADR R1,R4;
    BL打印
    SWI SWI_Exit;完成UnpackIEEE
    LDR R1,SMASK;加载符号位掩码为R1
    LDR R2,EMASK;装载指数面具到R2
    LDR R3,GMASK;加载尾数面具到R3
    和R4,R0,R1;报考标志面膜IEEE和保存到R4
    和R5,R0,R2;报考指数面膜IEEE和保存到R5
    和R6,R0,R3;报考尾数面膜IEEE和保存到R6
    MOV PC,R14;返回ConvToTNS
打印MOV R2,#8;半字节计数= 8
LOOP MOV R0,R1,LSR#28;得到最高蚕食
    CMP R0,#9; hexanumber 0-9或A-F
    ADDGT R0,R0,#A-10; ASCII字母
    变坏R0,R0,#0; ASCII数字
    SWI SWI_WriteC;打印字符
    MOV R1,R1,LSL#4;移左边的一个半字节
    SUBS R2,R2,#1;递减计数半字节
    BNE LOOP;如果有更多的蚕食,环回
    MOV PC,R14;返回
IEEE DCD 0x40280000 2.75或40280000
TNS DCD 0x28000101 2.75或28000101
SMASK DCD为0x80000000;签位掩码
EMASK DCD 0x7F800000;指数面具
GMASK DCD 0x007FFFFF;有效数字面膜
STRING DCB你好,0
    结束


解决方案

我想我知道明白你想要达到的目的。

我写了一个使用十进制数15.75的程序。结果
这个号码被存储在IEEE754格式。结果
它首先被转换为TNS格式转换的号码打印到控制台。
然后数转换回IEEE745格式。
转换后的数字打印到控制台,然后退出程序。

本程序为ARM7编写的。

看看在code。如果这听起来像这是你要实现的目标是什么:

  ENTRY
        LDR R0,IEEE;加载IEEE格式#到R0
        BL ieeetotns;分公司IEEE TNS的转换子程序
        BL打印;分公司打印的编号安慰
        BL tnstoieee;分公司TNS到IEEE转换子程序
        BL打印;分公司打印的编号安慰
        SWI SWI_Exit;退出程序        ;装载IEEE面具到寄存器
ieeetotns LDR R1,SIGNMASK;装载标志面具到R1
            LDR R2,IEEEEXPMASK;装载IEEE指数面具到R2
            LDR R3,IEEESIGMASK;装载IEEE尾数面具到R3            ;从转换到IEEE TNS
            和R4,R0,R1;解压符号位,存放于R4
            和R5,R2,R0;指数的初始解包,存放于R5
            MOV R5,R5,LSR#23;移指数权23位
            ADD R5,R5,#129;加129(10)到指数来校正TNS过量编码
            和R6,R3,R0;尾数的初始解包,存放于R6
            ADD R6,R7,R6,LSL#8;移动尾数左边8位,杀死LSB
            ORR R0,R4,R5;包装标志和指数
            ORR R0,R0,R6;包尾数带符号和指数,
                                    ; R0现在拥有IEEE TNS的转换字
            MOV PC,LR;返回主子程序        ;加载TNS面具
tnstoieee LDR R1,SIGNMASK;装载标志面具到R1
            LDR R2,TNSSIGMASK; TNS加载有效数字掩盖到R2
            LDR R3,TNSEXPMASK;加载TNS指数掩盖到R3        ;转换回IEEE
            和R4,R0,R1;解压符号位
            和R5,R2,R0;尾数的初始解包,存放于R5
            MOV R5,R5,LSR#8;移位尾数正确的8位
            和R6,R3,R0;指数的初始解包,存放于R6
            SUB R6,R6,#129;减去129纠正编码过剩
            ADD R6,R7,R6,LSL#23;移位指数留下23位        ;包装转换后的数字为R0
            ORR R0,R4,R5;包装标志和尾数
            ORR R0,R0,R6;包指数与符号和尾数,
                                    ; R0现在持有TNS符合IEEE转换字
            MOV PC,LR;返回主子程序打印MOV R2,#8;半字节= 8计数
            MOV R1,R0;移动号码R1
            MOV R3,R0;存储转换数R3供以后
LOOP MOV R0,R1,LSR#28;获取顶级轻咬
            CMP R0,#9;十六进制数字0-9或A-F?
            ADDGT R0,R0,#A-10; ASCII A-F
            变坏R0,R0,#0; ASCII 0-9
            SWI SWI_WriteC;打印字符安慰
            MOV R1,R1,LSL#4;移左边的一个半字节
            SUBS R2,R2,#1;递减计数轻咬
            BNE LOOP;如果有更多的蚕食再次循环
            MOV R0,#10;装载10到R0,ASCII code表示回车
            SWI SWI_WriteC;打印回车控制台
            MOV R0,R3;将转换后的数字回R0
            MOV PC,LR;返回主子程序
IEEE DCW为0x0000,0x417C; IEEE再$ 15.75(10)芘$ psentation,417C0000(16),
                                ; 01000001011111000000000000000000(2)
TNS DCW 0x0103,0x7C00; TNS再$ 15.75 p $ psentation(10),7C000103(16),
                                ; 01111100000000000000000100000011(2)
                                ;这不是在程序中使用,只是这里的转换比较SIGNMASK DCW为0x0000,为0x8000;掩码符号位
IEEEEXPMASK DCW为0x0000,0x7F80;掩码IEEE指数
IEEESIGMASK DCW 0xFFFF的,0X007F;掩码IEEE有效数字
TNSSIGMASK DCW 0xFE00,0x7FFF的;对于面膜有效数字TNS
TNSEXPMASK DCW 0x01FF,为0x0000;掩码TNS指数
结束

I am trying to write a program that will convert a number from ieee to TNS (big endian), and vice versa. I'm very new to ARM and assembly in general. I'm not getting an error, its just not working as intended and I'd appreciate it if anyone could look at it. Every line is commented, the sub routine actually in question here is the "unpack ieee" procedure, it is not working as intended and I cannot see why. EDIT: IEEE and TNS numbers have 3 parts, I am attempting to "grab" or seperate the 3 parts using the masks. The unpack procedure is using the masks to place each part into a seperate register so that I can manipulate each part in order to convert it. Currently I am trying to confirm that the unpack procedure works by calling it, and then printing the registers. The numbers are either not printing or printing incorrect results.end edit I have not written the conversion routines yet, but I have a psudocode algorithm I can post if you'd like. Just let me know if there is anything else you'd like to know. The code:

AREA Conversion, CODE
SWI_WriteC  EQU &0          ;output character in r0 
SWI_WriteL  EQU &2          ;output String in r0
SWI_Exit    EQU &11         ;finish program
    ENTRY

    ADR r0, STRING  ;load string
    SWI SWI_WriteL  ;print string
    LDR r1, IEEE    ;load IEEE num into r0
    BL  Print       ;print number
    BL  UnpackIEEE  ;call UnpackIEEE subroutine
    ADR r1, r4      ;
    BL  Print
    SWI     SWI_Exit    ;finish

UnpackIEEE
    LDR r1, SMASK   ;load the sign bit mask into r1 
    LDR r2, EMASK   ;load the exponent mask into r2
    LDR r3, GMASK   ;load the significand mask into r3
    AND r4, r0, r1  ;apply sign mask to IEEE and save into r4
    AND r5, r0, r2  ;apply exponent mask to IEEE and save into r5
    AND r6, r0, r3  ;apply significand mask to IEEE and save into r6
    MOV     pc, r14     ;return

ConvToTNS


Print   MOV r2,#8       ;count of nibbles = 8
LOOP    MOV r0,r1,LSR #28   ;get top nibble
    CMP     r0, #9      ;hexanumber 0-9 or A-F
    ADDGT   r0,r0, #"A"-10  ;ASCII alphabetic
    ADDLE   r0,r0, #"0" ;ASCII numeric
    SWI     SWI_WriteC  ;print character
    MOV r1,r1,LSL #4    ;shift left one nibble
    SUBS    r2,r2, #1   ;decrement nibble count
    BNE LOOP        ;if more nibbles,loop back
    MOV     pc, r14     ;return


IEEE    DCD 0x40280000  ;2.75 or 40,280,000
TNS     DCD 0x28000101  ;2.75 or 28,000,101
SMASK   DCD 0x80000000  ;Sign bit mask
EMASK   DCD 0x7F800000  ;Exponent mask
GMASK   DCD     0x007FFFFF  ;Significand mask
STRING  DCB "HI THERE",0
    END

解决方案

I think I know understand what you are trying to achieve.

I wrote up a program that uses the decimal number 15.75.
This number is stored in IEEE754 format.
It is first converted to TNS format the converted number is printed to the console. The number is then converted back to IEEE745 format. The converted number is printed to the console then the program exits.

This program is written for ARM7.

Take a look at the code if it sounds like that is what you are trying to achieve:

ENTRY
        LDR r0, IEEE        ; Load IEEE formatted # into r0
        BL  ieeetotns       ; Branch to IEEE to TNS conversion subroutine
        BL  Print           ; Branch to print number to console
        BL  tnstoieee       ; Branch to TNS to IEEE conversion subroutine
        BL  Print           ; Branch to print number to console
        SWI     SWI_Exit    ; Exit Program

        ; Load IEEE Masks into registers
ieeetotns   LDR r1, SIGNMASK        ; Load sign mask into r1
            LDR r2, IEEEEXPMASK     ; Load IEEE exponent mask into r2
            LDR r3, IEEESIGMASK     ; Load IEEE significand mask into r3

            ; Convert from IEEE to TNS
            AND r4, r0, r1          ; unpack sign bit, store in R4
            AND r5, r2, r0          ; initial unpack of exponent, store in r5
            MOV r5, r5, LSR #23     ; shift exponent right 23 bits  
            ADD r5, r5, #129        ; add 129(10) to exponent to correct excess encoding for TNS
            AND r6, r3, r0          ; initial unpack of significand, store in r6
            ADD r6, r7, r6, LSL #8  ; shift significand left 8 bits, kill off LSB
            ORR r0, r4, r5          ; pack sign and exponent
            ORR r0, r0, r6          ; pack significand with sign and exponent, 
                                    ; r0 now holds IEEE to TNS converted word
            MOV PC, LR              ; Return to main subroutine 

        ; Load TNS Masks
tnstoieee   LDR r1, SIGNMASK        ; Load sign mask into r1
            LDR r2, TNSSIGMASK      ; Load TNS Significand mask into r2
            LDR r3, TNSEXPMASK      ; Load TNS Exponent mask into r3

        ; Convert back to IEEE
            AND r4, r0, r1          ; unpack sign bit
            AND r5, r2, r0          ; initial unpack of significand, store in r5
            MOV r5, r5, LSR #8      ; Shift significand right 8 bits
            AND r6, r3, r0          ; Initial unpack of exponent, store in r6
            SUB r6, r6, #129        ; Subtract 129 to correct excess encoding
            ADD r6, r7, r6, LSL #23 ; Shift exponent left 23 bits

        ; Pack the converted number into r0
            ORR r0, r4, r5          ; Pack sign and significand
            ORR r0, r0, r6          ; Pack exponent with sign and significand, 
                                    ; r0 now holds TNS to IEEE converted word
            MOV PC, LR              ; Return to main subroutine

Print       MOV r2, #8              ; Count of nibbles = 8
            MOV r1, r0              ; Move number to r1
            MOV r3, r0              ; Store converted number in r3 for later
LOOP        MOV r0, r1, LSR #28     ; Get top nibble
            CMP r0, #9              ; Hex number 0-9 or A-F?
            ADDGT   r0, r0, #"A"-10 ; ASCII A-F
            ADDLE   r0, r0, #"0"    ; ASCII 0-9
            SWI SWI_WriteC          ; Print character to console
            MOV r1, r1, LSL #4      ; Shift left one nibble
            SUBS    r2, r2, #1      ; Decrement nibble count
            BNE     LOOP            ; If more nibbles loop again
            MOV r0, #10             ; Load 10 into r0, ASCII code for carriage return
            SWI SWI_WriteC          ; Print carriage return to console
            MOV r0, r3              ; Move converted number back to r0
            MOV PC, LR              ; Return to main subroutine     


IEEE        DCW 0x0000, 0x417C  ; IEEE Representation of 15.75(10), 417C0000(16), 
                                ; 01000001011111000000000000000000(2)
TNS         DCW 0x0103, 0x7C00  ; TNS  Representation of 15.75(10), 7C000103(16), 
                                ; 01111100000000000000000100000011(2)
                                ; This is not used in program, simply here for comparison of conversions

SIGNMASK    DCW 0x0000, 0x8000  ; Mask for sign bit
IEEEEXPMASK DCW 0x0000, 0x7F80  ; Mask for IEEE Exponent
IEEESIGMASK DCW 0xFFFF, 0x007F  ; Mask for IEEE Significand
TNSSIGMASK  DCW 0xFE00, 0x7FFF  ; Mask for TNS Significand
TNSEXPMASK  DCW 0x01FF, 0x0000  ; Mask for TNS Exponent
END 

这篇关于ARM数转换程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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