meda.gharib 0 Newbie Poster

Hi everyone I'm stuck on a school project. The Following is the prompt:

Write an assembly language program that prompts the user to enter a string to be interpreted as an 8-digit hexadecimal number. Your program must convert the ASCII string representation of this hexadecimal number into a 32-bit unsigned binary number. Then, your program must prepare and store an ASCII string for the octal (base 8) representation of the same number and print it out.Your program should generate an error if the input string contains a character that is not 0 through 9 or A through F (except for the linefeed at the end). You may disallow lower case 'a' through 'f' in the hexadecimal representation. You may also assume that any input string that does not have exactly 8 characters is invalid (not counting the linefeed).

I am having trouble with what I should do next after I get the input from the user. I converted "1" to simply 1, so I can get the binary value (also "A" to 10 and so on), but I'm not sure if that's right. Any guidance or psuedocode would be great.

; File: toupper.asm last updated 09/26/2001
; Convert user input to upper case.
; Assemble using NASM:  nasm -f elf toupper.asm
; Link with ld:  ld toupper.o

%define STDIN 0
%define STDOUT 1
%define SYSCALL_EXIT  1
%define SYSCALL_READ  3
%define BUFLEN 256

        SECTION .data                   ; initialized data section

msg1:   db "Enter string: "             ; user prompt
len1:   equ $-msg1                      ; length of first message

msg2:   db "Original: "                 ; original string label
len2:   equ $-msg2                      ; length of second message

msg3:   db "Convert:  "                 ; converted string label
len3:   equ $-msg3

msg4:   db 10, "Read error", 10         ; error message
len4:   equ $-msg4

        SECTION .bss                    ; uninitialized data section
buf:    resb BUFLEN                     ; buffer for read
newstr: resb BUFLEN                     ; converted string
rlen:   resb 4                          ; length

        SECTION .text                   ; Code section.
        global  _start                  ; let loader see entry point

_start: nop                             ; Entry point.
start:                                  ; address for gdb

        ; prompt user for input
        mov     eax, SYSCALL_WRITE      ; write function
        mov     ebx, STDOUT             ; Arg1: file descriptor
        mov     ecx, msg1               ; Arg2: addr of message
        mov     edx, len1               ; Arg3: length of message
        int     080h                    ; ask kernel to write

        ; read user input
        mov     eax, SYSCALL_READ       ; read function
        mov     ebx, STDIN              ; Arg 1: file descriptor
        mov     ecx, buf                ; Arg 2: address of buffer
        mov     edx, BUFLEN             ; Arg 3: buffer length
        int     080h

        ; error check
        mov     [rlen], eax             ; save length of string read
        cmp     eax, 9                  ; check if any chars read
        je      read_OK                 ; >0 chars read = OK


        mov     eax, SYSCALL_WRITE      ; ow print error mesg
        mov     ebx, STDOUT
        mov     ecx, msg4
        mov     edx, len4
        int     080h
        jmp     exit                    ; skip over rest


        ; Loop for upper case conversion
        ; assuming rlen > 0
        mov     ecx, [rlen]             ; initialize count
        mov     esi, buf                ; point to start of buffer
        mov     edi, newstr             ; point to start of new string

        mov     al, [esi]               ; get a character
        inc     esi                     ; update source pointer
        cmp     al, 10                  ; line feed character?
        je      L1_end
        cmp     al, '0'                 ; less than '0'?
        jb      read_ERROR
        cmp     al, '9'                 ; more than '9'?
        ja      check_Letter
        mov     dl, '0'                 ; ASCII value of 0 moved to dl              
        sub     al, dl                  ; subtracting ASCII of 0 from input
        jmp     L1_cont

        cmp     al, 'A'                 ; less than 'A'?
        jb      read_ERROR
        cmp     al, 'F'                 ; more than 'F'?
        ja      read_ERROR
        mov     dl, 'F'                 ; ASCII value of F moved to dl              
        sub     dl, al                  ; subtracting ASCII of F from input
        add     dl, 10                  ; difference added to ASCII of 10
        mov     al, dl                  ; final value moved back to al
        jmp     L1_cont

        mov     [edi], al               ; store char in new string
        inc     edi                     ; update dest pointer
        dec     ecx                     ; update char count
        jnz     L1_top                  ; loop to top if more chars


        ; print out user input for feedback
        mov     eax, SYSCALL_WRITE      ; write message
        mov     ebx, STDOUT
        mov     ecx, msg2
        mov     edx, len2
        int     080h

        mov     eax, SYSCALL_WRITE      ; write user input
        mov     ebx, STDOUT
        mov     ecx, buf
        mov     edx, [rlen]
        int     080h

        ; print out converted string
        mov     eax, SYSCALL_WRITE      ; write message
        mov     ebx, STDOUT
        mov     ecx, msg3
        mov     edx, len3
        int     080h

        mov     eax, SYSCALL_WRITE      ; write out string
        mov     ebx, STDOUT
        mov     ecx, newstr
        mov     edx, [rlen]
        int     080h

        ; final exit
exit:   mov     eax, SYSCALL_EXIT       ; exit function
        mov     ebx, 0                  ; exit code, 0=normal
        int     080h                    ; ask kernel to take over
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.