I need some advice with a small program for school. If you could just point me in the right direction I would really appreciate it. I am using CodeWarrior coding in assembly language for the TWR-S12G128 Processor Module. My goal is to get the LEDs turn on and off with a delay of 1 second. Here is what my code looks like:
LDS #$4000 ; Initializing SP
LDAA #$FF
STAA DDRA ; Defines Port A as output
Back LDAA #$FF
STAA PORTA ; Turning all LEDs ON
JSR Delay
LDAA #$00
STAA PORTA ; Turning all LEDs OFF
JSR Delay
BSR Back
Delay PSHX ; 2-clock cycle
PSHY ; 2
LDY #20 ; 2-clock cycle
LOOP1 LDX #$FFFF ; 2
LOOP2 DEX ; 1-clock cycle
NOP ; 1-clock cycle
BNE LOOP2 ; 3-clock cycles/last cycle is 1
DEY ; 1
BNE $FF ; 3-clock cycles/last cycle is 1
PULY LOOP1 ; 3-clock cycle
PULX ; 3-clock cycle
RTS ; 5-clock cycle
There error that I am getting is :
Error : A2400: End of Line expected
main.asm line 58
Project: Project_4.mcp, Target: Standard, Source File: main.asm
Error : Compile failed
Project: Project_4.mcp, Target: Standard, Source File: main.asm
I don't know a great deal about the Freescale architecture but it's very unusual for any architecture to combine a pull instruction with a label.
The bne $ff is also unusual since that does normally specify a label.
I would be thinking that those two instructions should be more along the lines of:
bne loop1
puly
That makes more sense in that the pull instruction loses the label and the nested loops are properly constructed.
The $FF on the BNE line is not proper. I think it's a typo. I just worked this out with my professor a few hours ago. Here is the code that will give you the 1 second delay and continuously cycle the 4 LEDs on and off:
ABSENTRY Entry ; Application entry point
RAMStart EQU $2000
ROMStart EQU $C000
ORG RAMStart
; Insert here your data definition.
PTT EQU $240
DDRT EQU $242
; code section
ORG ROMStart
Entry:
_Startup:
LDS #$4000
Back LDAA #$FF
STAA DDRT
LDAA #$FF
STAA PTT
JSR Delay
LDAA #$00
STAA PTT
JSR Delay
BSR Back
Delay PSHX ; 2-clock cycle
PSHY ; 2
LDY #20 ; 2-clock cycle
LOOP1 LDX #$FFFF ; 2
LOOP2 DEX ; 1-clock cycle
NOP ; 1-clock cycle
BNE LOOP2 ; 3-clock cycles/last cycle is 1
DEY ; 1
BNE LOOP1 ; 3-clock cycles/last cycle is 1
PULY ; 3-clock cycle
PULX ; 3-clock cycle
RTS ; 5-clock cycle
ORG $FFFE
DC.W Entry ; Reset Vector
If someone would be so kind as to help me with the math. I get the 65,535 * 20 for the loops, but with the 6.25MHz clock, I end up getting .209 secs as the final amount for the delay, but I know it's suppose to be 1 sec. What am I not seeing?
Related
I have a text file where two different columns are having the same name. As shown in the following figure.
Let's say for SystBP, I need to change the first SystBP to SystBP_B and the second SystBP to SystBP_E.
Could someone kindly offer me some help on this?
When programming in SAS Base You should sometimes not expect SAS to read column names from a text file and interpret them as variable names.
You have to instruct SAS what the first data row is, where the values are written and how they should be interpreted (text, number, date, ...) You do that with an infile and an input statement in a data step.
As you write the code yourself, you have complete control.
data READ_FROM_TXT;
infile "C:\myFolder\myFile.txt" firstobs=3 truncover;
* firstobs=3 makes SAS skip the first 2 observations;
* truncover avoids jumping to the next line when the last variable is missing or too short ;
input
#01 ID 2.
#05 Week 4.
#11 SystBP_B 6.
#19 DiastBP_B 6.
...
#41 SystBP_E 6.
#49 DiastBP_E 6.
...
;
* #11 SystBP_B 6. instructs SAS to interpret positions 11 to 16 as a number
* and assign the value to variable SystBP_B;
run;
As you inserted the data as an image, not as text, using markup, I had to guess the positions, so you will have to correct them.
I would make timing into observations.
data test;
infile cards4 firstobs=2;
input id :$8. week #;
do time = 'STR','END';
input SystBP DiastBP Pulse Stress #;
output;
end;
cards;
ID Week SystBP DiastBP Pulse Stress SystBP DiastBP Pulse Stress
1 1 134 44 66 5.8 134 44 66 5.8
;;;;
run;
The INFILE option FIRSTOBS= will let you INPUT the data starting in row 3.
Data file: C:\temp\bp-survey.txt
Start End
ID Week SystBP DiastBP Pulse Stress SystBP DiastBP Pulse Stress
1 1 134 44 66 5.8 134 44 66 5.8
...
Program
filename survey 'c:\temp\bp-survey.txt';
data want;
infile survey firstobs=3;
input
ID Week
SystBP_start DiastBP_start Pulse_start Stress_start
SystBP_end DiastBP_end Pulse_end Stress_end
;
run;
ods html ;
proc print data=want;
run;
Is there a way to read a z/OS JCL input stream more than once? (one that comes from a //SYSIN DD *). I know I could cache the stream the first time I read it, and then read from the cached data, but I'm not interested in that solution.
Note: the language is Assembler
Depends on the language. This answer provides an example in HLASM and a reference to the 'C' Language reference at the end.
For Assembler you'll need to REWIND when you CLOSE the DCB. See the label at FINISH to see how this is done.
There may be other ways but this worked for me on z/OS 2.4
PRINT NOGEN
* ------------------------------------------------------------------- *
* *
* SYSIN2 *
* *
* #author Hogstrom *
* *
* Test to see if one can re-read SYSIN more than one time. *
* *
* ------------------------------------------------------------------- *
R0 EQU 0
R1 EQU 1
R2 EQU 2
R3 EQU 3 * Number of times to loop
R4 EQU 4
R5 EQU 5
R6 EQU 6
R7 EQU 7
R8 EQU 8
R9 EQU 9
R10 EQU 10
R11 EQU 11
R12 EQU 12 * Base Register
R13 EQU 13
R14 EQU 14
R15 EQU 15
*
SYSIN2 CSECT
STM R14,R12,12(R13)
LR R12,R15
USING SYSIN2,12
*
ST R13,SaveArea+4
LA R0,SaveArea
ST R0,8(R13)
LA R13,SaveArea
*
OPEN (SYSIN,(INPUT))
OPEN (SYSOUT,(OUTPUT))
LA R3,3 Number of times to read SYSIN
*
GETAGAIN DS 0H
GET SYSIN,INREC Read the next rec
PUT SYSOUT,INREC Write that bad boy out
B GETAGAIN
FINISH DS 0H Invoked at End of Data of SYSIN
CLOSE (SYSIN,REWIND) Close SYSIN and rewind
OPEN (SYSIN,(INPUT)) Open it up again
BCT R3,GETAGAIN Repeat the madness
*
CLOSE SYSIN
CLOSE SYSOUT
*
L R13,SaveArea+4
LM R14,R12,12(R13)
XR R15,R15
BR R14
*
SYSIN DCB DSORG=PS,MACRF=(GM),DDNAME=SYSIN,EODAD=FINISH, *
RECFM=FB,LRECL=80,BLKSIZE=0
SYSOUT DCB DSORG=PS,MACRF=(PM),DDNAME=SYSOUT, *
RECFM=FBA,LRECL=133,BLKSIZE=0
*
INREC DC CL132' '
SaveArea DS 18F
LTORG
END
Assemble the above and execute this JCL
//SYSIN2 JOB (CCCCCCCC),'HOGSTROM',
// MSGLEVEL=(1,1),
// MSGCLASS=O,
// CLASS=A,
// NOTIFY=&SYSUID
//*
//STEP1 EXEC PGM=SYSIN2
//STEPLIB DD DSN=USER1.TEST.LOADLIB,DISP=SHR
//*
//SYSIN DD *
REC 1 OF 3
REC 2 OF 3
REC 3 OF 3
/*
//SYSOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
And you'll get this output
You'll see the same SYSIN data repeated three times.
For a 'C' program this reference in the IBM documentation for the C Compiler provides some hints about rewinding.
To open an in-stream data set, call the fopen() or freopen() library
function and specify the ddname of the data set. You can open an
in-stream data set only for reading. Specifying any of the update,
write, or append modes fails. Once you have opened an in-stream data
set, you cannot acquire or change the file position except by
rewinding. This means that calls to the fseek(), ftell(), fgetpos(),
and fsetpos() for in-stream data sets fail. Calling rewind() causes
z/OS XL C/C++ to reopen the file, leaving the file position at the
beginning.
What you're looking for is possible but the implementation is language dependent.
I have a very simple delay routine to produce delay bigger that 0.5 sec; the idea is to use TMR2, PR2 and PIC12F683; but it produces an error 116
DELAY MACRO
BANKSEL T2CON
MOVLW 0x76 ; put register w=118
MOVWF T2CON ; T2CON=W=1110111 Start TMR2 and set Postsacaler to 1110
BANKSEL PR2
MOVLW 0xC8
MOVWF PR2 ; Put PR2 to 200
**Lazo
BANKSEL T2CON
BTFSS T2CON,TOUTPS0 ;when TMR2= PR2 bit 3 (post scaler) is incremented from 1110 to 1111 then jump next instruction and end macro
GOTO Lazo****
endm
Error[116] C:\USERS\MUTANTE\MPLABXPROJECTS\CLAXON.X\MACROSDEF.INC 12 : Address label duplicated or different in second pass (Lazo)
Any idea why i got this error in the Lazo loop
When a macro is instantiated, its content is inserted verbatim, and that is what the assembler sees. If you define a label inside of a macro and then call the macro more than once, the label is defined more than once, and you will get this error.
Labels in macros must use the LOCAL directive inside of the macro definition, thus:
DELAY MACRO
LOCAL Lazo
BANKSEL T2CON
MOVLW 0x76 ; put register w=118
MOVWF T2CON ; T2CON=W=1110111 Start TMR2 and set Postsacaler to 1110
BANKSEL PR2
MOVLW 0xC8
MOVWF PR2 ; Put PR2 to 200
Lazo
BANKSEL T2CON
BTFSS T2CON,TOUTPS0 ; when TMR2= PR2 bit 3 (post scaler) is
; incremented from 1110 to 1111 then jump
; next instruction and end macro
GOTO Lazo
ENDM
in first, sorry for my bad english, i'm french.
At the moment, i learn asm with fasm to test boot sector programming.
I have make a simple boot program, i have compiled it and i write boot.bin in first sector of my usb.
But when i boot on my PC or in virtualbox, drive isn't found....
Boot sector code:
;=======================================================================
; a simpliest 1.44 bootable image by shoorick ;)
;=======================================================================
_bs equ 512
_st equ 18
_hd equ 2
_tr equ 80
;=======================================================================
org 7C00h
jmp start
nop
;=====================================================
db "HE-HE OS"; ; 8
dw _bs ; b/s
db 1 ; s/c
dw 1 ; rs
db 2 ; fats
dw 224 ; rde
dw 2880 ; as
db 0F0h ; media
dw 9 ; s/fat
dw _st ; s/t
dw _hd ; h
dd 0 ; hs
dd 0 ; --
db 0 ; drv
db 0 ; --
db 29h ; ebr
dd 0 ; sn
db "NO NAME "; ; 11
db "FAT12 "; ; 8
;=====================================================
start:
mov ax,cs
mov ds,ax
mov cx,count
mov si,hello
mov bx,7
mov ah,0Eh
##:
lodsb
int 10h
loop #B
xor ah,ah
int 16h
int 19h
hello db "Hi! This is disk-invalid!"
count = $ - hello
;=======================================================================
rb 7E00h-2-$
db 055h,0AAh
;=======================================================================
This code is provide by examples of fasm's website.
there are couple of reasons why a bootloader wont work:
the bootloader is not in the first sector of the USB/Floppy/etc.
the bootloader is not EXACTLY 512 bytes long
you are missing the 0xAA55 signature at the last 2 bytes of the bootloader
in your example i assume you have the wrong bootloader size ( it is not 512 bytes )
try replacing
rb 7E00h-2-$
db 055h,0AAh
with
TIMES 510-($-$$) DB 0
DW 0xAA55
this ensures that your file is exactly 512 bytes long and that is has the required bootloader signature
I have gone through the basics of Global Descriptor Table (GDT) and i have successfully written a "GDT.inc" using asm , so that we can easily include it in our bootloader. As a baby step i have configured the Code Descriptor and Data Descriptor to read and write from the first byte to byte 0xFFFFFFFF in memory (any portion in memory)
; null descriptor
dd 0 ; null descriptor--just fill 8 bytes with zero
dd 0
; code descriptor: ; code descriptor. Right after null descriptor
dw 0FFFFh ; limit low
dw 0 ; base low
db 0 ; base middle
db 10011010b ; access
db 11001111b ; granularity
db 0 ; base high
; data descriptor: ; data descriptor
dw 0FFFFh ; limit low (Same as code)
dw 0 ; base low
db 0 ; base middle
db 10010010b ; access
db 11001111b ; granularity
db 0 ; base high
Now my purpose is to create two separate regions using GDT .For example , first 512B as one region and next 512B as another region and leaving the space left as unused.
What can i do for that ?
you can just change where your base address & limit registers .
so in the example you gave
for code descriptor
.base = 0x0
.limit = 0x200 //512 byte
for data descriptor
.base = 0x200
.limit = 0x200
then you have the rest of your memory after the 1 KB empty
you can check "http://wiki.osdev.org/GDT_Tutorial" for more explanation