Recent Posts

Pages: 1 ... 8 9 [10]
91
Hello,
So i am new to assembler and am struggling trying to read a value such as 10001010 using either
call read_int
or
call read_char
and then taking that input from the keyboard and splitting into an array such as
[1][0][0][0][1][0][1][0]

Is this even possible?
thank you for any advice, and i appreciate any coding help.  Here is what i have so far.

%include "/usr/local/share/asm_io.inc"

segment .data
    message       db "Enter code?: ",0
   
    var1          dd 123
    bitmask       dd 1,1,1,0,0,0,1,1
    mask          dd 11100011
   
segment .bss
    cook resd 8

segment .text
   global  asm_main

asm_main:
   push   ebp
   mov    ebp, esp
   ;********** CODE STARTS HERE **********


        ;;;;;;;;;;;;;;;;
        ;INIT
        ;;;;;;;;;;;;;;;;
        mov eax, 0
        mov ebx, 0
        topinit:
        cmp ebx, 8
        jge endinit
        mov DWORD [cook + ebx * 4], eax
        inc ebx
        jmp topinit
        endinit:

        ;;;;;;;;;;;;;;;;
        ;cook
        ;;;;;;;;;;;;;;;;
        cld ;clear destination flag
       
        mov eax, message        ;display message
        call print_string
       
        ;call read_char
        call read_int

        mov DWORD [var1], eax

        call read_char  ;\n

        mov eax, DWORD [var1]
       
        dump_regs 1
        call print_int

        jmp endloop2
       
                               
        endloop2:     
        call print_nl

   ; *********** CODE ENDS HERE ***********
   mov      eax, 0
   mov      esp, ebp
   pop      ebp
   ret
92
Programming with NASM / Help with basic assemly language program
« Last post by kingpoop on July 01, 2021, 04:51:02 AM »
Can anyone help me see what i am doing wrong?

I basically am trying to ask y/n questions to add ingredients for ordering a hamburger.

The code asks the first question then runs through the loop until the end. 

I need to ask each question and enter y or n

thanks,


%include "/usr/local/share/csc314/asm_io.inc"

;10 newline \n
;32 space
;0  \0 null

segment .data
    welcome       db  "Welcome to Burger Shack!",10,"Please choose your toppings: answer y for Yes, n for No",10,0
    lettuceprompt db  "Lettuce?    :",0
    cheeseprompt  db  "Cheese?     :",0
    tomatoeprompt db  "Tomatoe?    :",0
    onionprompt   db  "Onion?      :",0
    pickleprompt  db  "Pickle?     :",0
    ketchupprompt db  "Ketchup?    :",0
    mayoprompt    db  "Mayonnaise? :",0
    mustardprompt db  "Mustard?    :",0

segment .bss
    ;8 ingredients
    ;   0        1       2       3       4       5       6      7    null
    ;lettuce, cheese, tomatoe, onion, pickle, ketchup, mayo, mustard \0
    order resd 9

segment .text
   global  asm_main

asm_main:
   push   ebp
   mov    ebp, esp
   ;********** CODE STARTS HERE **********


        ;;;;;;;;;;;;;;;;
        ;INIT
        ;;;;;;;;;;;;;;;;
        mov eax, 0
        mov ecx, 0
        topinit:
        cmp ecx, 8
        jge endinit
        mov DWORD [order + ecx * 4], eax
        inc ecx
        jmp topinit
        endinit:

        ;;;;;;;;;;;;;;;;
        ;ORDER
        ;;;;;;;;;;;;;;;;
        mov eax, welcome        ;display welcome message
        call print_string
               
        mov eax, 0
        mov ecx, 0              ;loop counter
        toploop1:

            cmp ecx, 8
            jge endloop1

            cmp ecx, 0
            je lettuce
       
            cmp ecx, 1
            je cheese
           
            cmp ecx, 2
            je tomatoe
           
            cmp ecx, 3
            je onion
           
            cmp ecx, 4
            je pickle
           
            cmp ecx, 5
            je ketchup
           
            cmp ecx, 6
            je mayo
           
            cmp ecx, 7
            je mustard
           
        next:
            inc ecx
            jmp toploop1
        endloop1:
            jmp endorder
       
        lettuce:
            mov eax, lettuceprompt    ;set lettuce prompt
            jmp readinput

        cheese:
            mov eax, cheeseprompt     ;set cheese prompt
            jmp readinput

        tomatoe:
            mov eax, tomatoeprompt    ;set tomatoe prompt
            jmp readinput

        onion:
            mov eax, onionprompt      ;set onion prompt
            jmp readinput
           
        pickle:
            mov eax, pickleprompt     ;set pickle prompt
            jmp readinput
           
        ketchup:
            mov eax, ketchupprompt    ;set ketchup prompt
            jmp readinput                                   

        mayo:
            mov eax, mayoprompt       ;set mayo prompt
            jmp readinput   
           
        mustard:
            mov eax, mustardprompt    ;set mustard prompt
            jmp readinput               

        readinput:
            call print_string         ;display prompt to screen
            call read_char            ;enter y/n
            mov cl, al                ;save input
            call read_char            ;\n
            call print_nl
            call print_char
            cmp cl, 'y'               ;add ingredient?
            je addtopping
            jmp next
           
        addtopping:
        mov eax, ecx
        call print_int
        call print_nl
        mov DWORD [order + ecx * 4], 1  ;set 1 for yes
        mov eax, 0
        jmp next
       
        endorder:
     
        ;;;;;;;;;;;;;;;;
        ;PRINT
        ;;;;;;;;;;;;;;;;
        call print_nl   ;newline
        mov ecx, 0
        toploop2:
        cmp ecx, 8
        jge endloop2
       
        mov eax, DWORD [order + ecx * 4]
        call print_int
        call print_nl
       
        inc ecx
        jmp toploop2
       
        endloop2:     

   ; *********** CODE ENDS HERE ***********
   mov      eax, 0
   mov      esp, ebp
   pop      ebp
   ret
93
Programming with NASM / Save register value in data variable (386)?
« Last post by mjrice on June 29, 2021, 03:34:52 AM »
This function returns the highest character in the input qword that contains ABCDEFGH, printed in hex. The high word mask is hard coded in mhigh. How does one move the two dwords pointed to by EAX into mhigh and mlow?


mrice@debian10-uni:~$ ./test
ABCDEFGH
              41


section .data
mhigh:  dw  255
mlow:   dw  0 

section .text  ;AND 64-bit 2nd arg source with 1st arg mask

global sqout_

sqout_:
  push  ebp
  mov   ebp, esp
  mov   eax, [ebp+8]      ;eax <- addr of 1st arg, mask
  mov   ecx, [ebp+12]     ;ecx <- addr of 2nd arg, source

  pop   ebp

  mov   eax, [ecx]
  mov   edx, [ecx+4]

  and   eax, [mhigh]
  and   edx, [mlow]
 
  ret
94
Programming with NASM / Re: Rotate 64-bit word
« Last post by mjrice on June 27, 2021, 03:20:28 PM »
Finally found a way to localize the masking variables to the RDLSTA function.. Using them to print a few characters on the low end of "ABCDEFGH". On to asm function SQOUT(MASK,WORD).

mrice@debian10-uni:~$ ./test
ABCDEFGH
H
G
F
E
mrice@debian10-uni:~$


! Create a mask for each of 8 characters
      INTEGER CP(8),COPY
      DATA CP(1)/Z'00000000000000FF'/
      DATA CP(2)/Z'000000000000FF00'/
      DATA CP(3)/Z'0000000000FF0000'/
      DATA CP(4)/Z'00000000FF000000'/
      DATA CP(5)/Z'000000FF00000000'/
      DATA CP(6)/Z'0000FF0000000000'/
      DATA CP(7)/Z'00FF000000000000'/
      DATA CP(8)/Z'FF00000000000000'/

  100 FORMAT(A8)
  110 FORMAT(Z16)
 
!      DO 30, I=1,8
!      WRITE(*,110) CP(I)
!   30 CONTINUE

      READ(*,100) IGET

      IWORD=ISHFT(IAND(IGET,CP(8)),0)
      WRITE(*,100) IWORD
      IWORD=ISHFT(IAND(IGET,CP(7)),-8)
      WRITE(*,100) IWORD
      IWORD=ISHFT(IAND(IGET,CP(6)),-16)
      WRITE(*,100) IWORD
      IWORD=ISHFT(IAND(IGET,CP(5)),-24)
      WRITE(*,100) IWORD

      END
95
Programming with NASM / Re: Rotate 64-bit word
« Last post by mjrice on June 26, 2021, 01:53:55 AM »
root@debian10-uni:/home/mrice# ./test
              FF
            FF00
          FF0000
        FF000000
      FF00000000
    FF0000000000
  FF000000000000
FF00000000000000
root@debian10-uni:/home/mrice# gfortran -c -fdefault-integer-8 -fdefault-real-8 -fno-range-check test.f95 -o test.o
root@debian10-uni:/home/mrice# gfortran test.o krot8left64.o -o test
root@debian10-uni:/home/mrice# ./test
ABCDEFGH
G

Reversed the order of  the masks and got the 7th character, the G. The computer that was used in he early 1960s must have been big endian?

Can't find a gfortran that will accept hexadecimals in a data statement. Tried gfortran-8. Now to write SQOUT, a function that will "squeeze out" individual characters as this fortran code does.  Another function, to come later, called SQIN will squeeze the output from SQOUT into a waiting, initially all blank, 64 bit word a character at a time.

A line from the fortran code of the SLIP document:

SYMBOL = SQIN(CP(8),SQOUT(CP(IC),CRDBUF(IW)),PLACE)

CP(8) should probably be changed to CP(1)? Also, since IC currently starts at 1 and increments upward, it should begin at 8 and decrement downward.  Or, easier, re-reverse the order of the masks? :-)


96
Programming with NASM / Re: Rotate 64-bit word
« Last post by mjrice on June 25, 2021, 04:15:32 PM »
Oops, asked for the G CP(7), shifted it rightward, got the B instead.

      READ(*,100) IGET
      IWORD=ISHFT(IAND(IGET,CP(7)),-8)

mrice@debian10-uni:~$ ./test
ABCDEFGH
B
mrice@debian10-uni:~$

Think of the variable IGET as one 64 bit  word  from an array of 10 of them read from a punched card.  The characters on the word are removed from that word one at a time and shoved one at a time into a waiting all blank 64 bit word from the left end, the same for each succeeding character, shifting earlier characters leftward, until a blank or a comma is found, then the word shifted leftward until all blanks, if any, are to the right of the other characters, forming a token which can be pushed up from the bottom of a waiting list. Encountering a right paren character completes the list. The function RDLSTA recursively reads sublists encountered in this process.

Looking for a way to data-ize the masks to be local to the function. Will try this later:

!      DATA CP(1:8)
!       /
!        Z'FF00000000000000',
!        Z'00FF000000000000',
!        Z'0000FF0000000000',
!        Z'000000FF00000000',
!        Z'00000000FF000000',
!        Z'0000000000FF0000',
!        Z'000000000000FF00',
!        Z'00000000000000FF'
!       /



97
Programming with NASM / Re: Rotate 64-bit word
« Last post by mjrice on June 24, 2021, 02:51:49 PM »
Btw, used your shifting function to create 8 masks I'll need for my next task. Just changed the  Rs to Ls in the shifting functions. Started at the low end with 255 rather than the high end with -72 quadrillion.

mrice@debian10-uni:~$ ./test
FF00000000000000
  FF000000000000
    FF0000000000
      FF00000000
        FF000000
          FF0000
            FF00
              FF

! Create a mask for each of 8 characters
      INTEGER CP,COPY
      DIMENSION CP(8)
  100 FORMAT(Z16)

      DO 10, I=1,8
      CP(I)=0
   10 CONTINUE

! Start with the low end
      CP(8)=255

! Shift the other 7 leftward from it
      DO 20, I=7,1,-1
      COPY=CP(I+1)
      CP(I)=KROT8LEFT64(COPY)
   20 CONTINUE

      DO 30, I=1,8
      WRITE(*,100) CP(I)
   30 CONTINUE

      END
98
Programming with NASM / Re: Rotate 64-bit word
« Last post by mjrice on June 24, 2021, 02:37:30 PM »
Ran this this morning.

! Sums structural list of real numbers, prints list and sum.
      dimension space(100)    !  Set aside list space
      call initas(space,100)

      l1 = 0
      l2 = 0
      idummy = list(l1)    !  Function list both assigns list-name to its argument and returns the list name
      idummy = list(l2)

      idummy = newbot(1.0,l1)
      idummy = newbot(6.0,l2)
      idummy = newbot(l2,l1)
      idummy = newbot(3.0,l1)
      call prlsts(l1,3)    !  3 means list is real numbers; 2 is characters; 1 is integers
      total = 0.0
      k = lrdrov(l1)       !  Create list reader
    1 x = advsel(k,f)    !  Advance reader structurally, (s), by element (e). Parameter f is a flag
    if (f .ne. 0) go to 2  !  Reader at end of list?
      total = total + x
      go to 1
    2 continue
      print *, total
      end

mrice@debian10-uni:~/slip/test$ ./test
                    BEGIN LIST
                         1.0000
                     BEGIN SUBLIST
                         6.0000
                     END SUBLIST
                         3.0000
                    END LIST
   10.000000000000000 
99
Programming with NASM / Re: Rotate 64-bit word
« Last post by mjrice on June 24, 2021, 01:26:24 PM »
Two figures attached, both from the ACM document "Symmetric List Processor," author Joseph Weizenbaum.

The part I'm working on now allows a user to enter a textual representation of a list, like the one in Fig. 3, from the keyboard, and construct from it an internal list, as shown in the diagrams. Currently lists can only be constructed programmatically.  Will post an example of that next.
100
Programming with NASM / Re: Rotate 64-bit word
« Last post by mjrice on June 24, 2021, 12:56:28 AM »
A lot of this is already implemented. Will send an example to give you a better idea of what SLIP all about.
Pages: 1 ... 8 9 [10]