News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

NASM uppercase conversion program issue

Started by silvercats, June 05, 2014, 07:39:22 PM

Previous topic - Next topic

silvercats

; Author           : Jeff Duntemann
; Description      : A simple program in assembly for Linux,using NASM 2.05,
;    demonstrating simple text file I/O (through redirection) for reading an
;    input file to a buffer in blocks, forcing lowercase characters to
;    uppercase, and writing the modified buffer to an output file.
;
; Run it this way:
;    uppercaser2 > (output file) < (input file)
;
; Build using these commands:
;    nasm -f elf -g -F stabs uppercaser2.asm
;    ld -o uppercaser2 uppercaser2.o
;
SECTION .bss                   ; Section containing uninitialized data
        BUFFLEN equ 1024       ; Length of buffer
        Buff:   resb BUFFLEN   ; Text buffer itself
SECTION .data              ; Section containing initialised data
SECTION .text              ; Section containing code
global  _start             ; Linker needs this to find the entry point!
_start:
                          ; This no-op keeps gdb happy...
        nop
; Read a buffer full of text from stdin:
read:
        mov eax,3         ; Specify sys_read call
        mov ebx,0         ; Specify File Descriptor 0: Standard Input
        mov ecx,Buff      ; Pass offset of the buffer to read to
        mov edx,BUFFLEN ; Pass number of bytes to read at one pass
        int 80h           ; Call sys_read to fill the buffer
        mov esi,eax       ; Copy sys_read return value for safekeeping
        cmp eax,0         ; If eax=0, sys_read reached EOF on stdin
        je Done           ; Jump If Equal (to 0, from compare)
; Set up the registers for the process buffer step:
        mov ecx,esi       ; Place the number of bytes read into ecx
        mov ebp,Buff      ; Place address of buffer into ebp
        dec ebp           ; Adjust count to offset
; Go through the buffer and convert lowercase to uppercase characters:
Scan:
        cmp byte [ebp+ecx],61h ; Test input char against lowercase 'a’
        jb Next          ; If below 'a’ in ASCII, not lowercase
        cmp byte [ebp+ecx],7Ah ; Test input char against lowercase 'z’
        ja Next          ; If above 'z’ in ASCII, not lowercase
                         ; At this point, we have a lowercase char
        sub byte [ebp+ecx],20h ; Subtract 20h to give uppercase...
Next:   dec ecx          ; Decrement counter
        jnz Scan         ; If characters remain, loop back
; Write the buffer full of processed text to stdout:
Write:
        mov eax,4        ; Specify sys_write call
        mov ebx,1        ; Specify File Descriptor 1: Standard output
        mov ecx,Buff     ; Pass offset of the buffer
        mov edx,esi      ; Pass the # of bytes of data in the buffer
        int 80h          ; Make sys_write kernel call
        jmp read         ; Loop back and load another buffer full
; All done! Let’s end this party:
Done:
        mov eax,1        ; Code for Exit Syscall
        mov ebx,0        ; Return a code of zero
        int 80H          ; Make sys_exit kernel call


this is the error I get when running the code (NASM is the assembler ). Thanks.

cat@cat-laptop:~/Desktop$ sudo ./uppercase2 >toUpper.txt <fromLow.txt
./uppercase2: 1: �f�f�f�tf�̀f��f=t?f��f�tfMg�: not found./uppercase2: 1:
arg�: not found
: not found2: 1:

dedndave

that looks like LINUX NASM code
we are a windows masm forum - so it looks a little strange   :P

there are 2 things that look odd

mov ebp,Buff
not sure about NASM syntax
but, that might move the contents (the first 4 bytes) of Buff into EBP

in masm syntax, we would use
mov ebp,offset Buff
this moves the address of Buff into EBP

the other thing is that EBP is used
again - i don't know about LINUX
but EBP may not be the best register to use, as it references the SS segment, not the DS segment

FORTRANS

Hi,

   NASM differentiates between Buff and [Buff] to avoid the use
of OFFSET.  So that should not be the problem.

Regards,

Steve N.

GoneFishing

Does the error message appear in your terminal in the same human unreadable form ?
It seems like the program didn't like one of the command line arguments . 

silvercats

yes, it shows like that In the Terminal in human unreadable form. Copied from the Terminal
This is a Linux(Ubuntu) problem and the code is an example from "Step by step assembly" by Jeff Dunteman. The book was written in 2009 though.

dedndave

it looks like older linux code (int 80h)
i think they have API functions now, somewhat similar to windows

Gunther

Hi silvercats,

please tell us your command line. It should look like that:

nasm -f elf32 uppercaser.asm -o uppercaser.obj


I'm not sure, if the linker command line is valid. Anyway, which example in the book is it? I've Jeff's booklet and can check it tomorrow evening, if that is fast enough for you. At the moment I'm not at home.

Gunther
You have to know the facts before you can distort them.

habran

Quote'a’ 'z’ Let’s
:dazzled:
don't you find it strange in your code ::)

your compiler probably don't understand Martian language  :greensml: 

try NASA instead of NASM :bgrin:
Cod-Father

jj2007

Quote from: habran on June 06, 2014, 02:29:07 PM
your compiler probably don't understand Martian language  :greensml: 

Some compilers understand Martian language, but internally they call it "UTF-8" 8)

habran

that compiler thinks probably that this is UFO-8  :biggrin:
Cod-Father

dedndave

it might be unicode text ?
displayed with the wrong codepage, maybe ?

habran

that's why NASM spat this garbage:
Quotecat@cat-laptop:~/Desktop$ sudo ./uppercase2 >toUpper.txt <fromLow.txt
./uppercase2: 1: �f�f�f�tf�̀f��f=t?f��f�tfMg�: not found./uppercase2: 1:
arg�: not found
:greenclp:
Cod-Father

Gunther

Jochen, Habran, Dave,

now the fun should stop. That's not a joke thread, but a serious question.

Gunther
You have to know the facts before you can distort them.

habran

we were just pointing out that silvercats is using either wrong assembler or wrong codepage :shock:
Cod-Father

Gunther

Quote from: habran on June 07, 2014, 05:50:48 AM
we were just pointing out that silvercats is using either wrong assembler or wrong codepage :shock:

The assembler is the right one. It's NASM syntax. The code page could be, but in that case he would see always garbage at the screen by typing any text or command.

Gunther
You have to know the facts before you can distort them.