ARM编号转换程序 [英] ARM number conversion program

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

问题描述

我正在尝试编写一个程序,将数字从 ieee 转换为 TNS(大端),反之亦然.总的来说,我对 ARM 和汇编非常陌生.我没有收到错误,只是没有按预期工作,如果有人能看一下,我将不胜感激.每一行都有注释,这里实际讨论的子程序是解包 ieee"程序,它没有按预期工作,我不明白为什么.IEEE 和 TNS 编号有 3 个部分,我试图使用掩码抓取"或分离这 3 个部分.解包过程使用掩码将每个部分放入单独的寄存器中,以便我可以操作每个部分以进行转换.目前,我试图通过调用它来确认解包过程是否有效,然后打印寄存器.数字要么没有打印出来,要么打印出错误的结果.结束编辑我还没有编写转换例程,但我有一个伪代码算法,如果你愿意,我可以发布.如果您还有什么想知道的,请告诉我.代码:

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. 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.

我编写了一个使用十进制数 15.75 的程序.
此号码以 IEEE754 格式存储.
它首先转换为 TNS 格式,转换后的数字会打印到控制台.然后将数字转换回 IEEE745 格式.转换后的数字打印到控制台然后程序退出.

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.

此程序是为 ARM7 编写的.

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天全站免登陆